Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions JAVA/AgeDay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ageday;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.LocalDate;
import java.time.Period;
import java.util.Scanner;
/**
*
* @author JSVS
*/
public class AgeDay {

public static void getAge(String input){
LocalDate dob = LocalDate.parse(input);
LocalDate curDate = LocalDate.now();
Period period = Period.between(dob, curDate);
System.out.print(period.getYears()+" years "+period.getMonths()+" and "+period.getDays()+" days\n");

}

public static void calculateBornDay(String s1) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf1 = new SimpleDateFormat("EEEEE");
Date d = sdf.parse(s1);
String s = sdf1.format(d);
System.out.println("The Born Day is on "+s.toUpperCase());
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ParseException {
// TODO code application logic here
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Please enter date of birth in YYYY-MM-DD: ");
String input = scanner.nextLine();
scanner.close();
System.out.print("Hello ,"+name+".Your current Age is : ");
getAge(input);
calculateBornDay(input);
}

}

42 changes: 42 additions & 0 deletions JAVA/ConstructorOddEven.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

package constructoroddeven;
import java.util.Scanner;

public class ConstructorOddEven {
int number ;

Scanner in = new Scanner(System.in);
public ConstructorOddEven(){
System.out.println("Enter any non-negative number ");
number = in.nextInt();
if(number<0){
System.out.println("Negative numbers cannot be evaluated\nPlease,Try again!!");
System.exit(0);
}


}
public void checkData(){
if(number%2==0){
System.out.println("The Given Number "+number+" is Even");
}else{
System.out.println("The Given Number "+number+" is Odd");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Creating an object
String ch ;
Scanner in = new Scanner(System.in);
do{
ConstructorOddEven myobj = new ConstructorOddEven();
myobj.checkData();
System.out.println("Do you want to continue[y/n]: ");
ch = in.nextLine();

}while(ch.equalsIgnoreCase("Y"));

}
}
65 changes: 65 additions & 0 deletions JAVA/LotteryDrawing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lotterydrawing;
import java.util.Scanner;
/**
*
* @author JSVS
*/
public class LotteryDrawing {
int k ,n;
public void getInputs(){
Scanner in = new Scanner(System.in);
System.out.println("How many Numbers do you need to draw?");
k = in.nextInt();
System.out.println("What is the highest number you need to draw? ");
n = in.nextInt();
int []numbers = new int[n];
int []result = new int[k];
// creating object to access the classes
inputData(numbers,result);
}
public void inputData(int[]numbers,int[]result){
for(int i = 0 ;i<numbers.length;i++){
numbers[i]=i+1;
}
for(int i = 0 ;i<result.length;i++){
int r = (int)(Math.random() * n);

result[i] = numbers[r];
numbers[r] = numbers[n-1];
n--;
}
sortArray(result);
System.out.println("Bet the following combinations .It'll wil make you rich!");
for(int x : result){
System.out.print(x+" ");
}

}
public static int[]sortArray(int [] arr){
for(int i = 0 ;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
if(arr[i]>arr[j]){
int temp = arr[i];
arr[i]=arr[j];
arr[j]= temp;
}
}
}
return arr;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Creating objec for the class LotteryDrawing
LotteryDrawing myobj = new LotteryDrawing();
myobj.getInputs();

}

}
68 changes: 68 additions & 0 deletions JAVA/Pairs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pairs;
import java.util.*;
/**
*
* @author JSVS
*/
public class Pairs {
public void diff(int[]arr,int n)
{ int di=0;int dif=0;
int diff = Integer.MAX_VALUE;
for (int i=0; i<n-1; i++)
for (int j=i+1; j<n; j++)
if ((arr[i] - arr[j])< diff){
diff = Math.abs((arr[i] - arr[j]));
di=arr[j];
dif = arr[i];
}
System.out.println("The minimum difference pairs are: "+di+ " "+dif);
}
public void diff(int[]A)
{ int n;int di=0; int dif=0;
n=A.length;
int diff = Integer.MIN_VALUE;
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++) {
if ((A[i]-A[j]>diff)) {
diff = A[i]-A[j];
di=A[i];
dif=A[j];
}
}
}

System.out.println("The maximum difference pairs are: "+di+ " "+dif);
}


/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a[],j;
System.out.println("Enter the size of the array : ");
Scanner in=new Scanner(System.in);
j=in.nextInt();
a = new int[j];
System.out.println("Enter the values :");
for(int i=0;i<j;i++)
{
int k;
k=in.nextInt();
a[i]=k;
}
Pairs ob=new Pairs();
ob.diff(a,j);
ob.diff(a);
}

// TODO code application logic here
}


22 changes: 22 additions & 0 deletions JAVA/Registeration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package registeration;

/**
*
* @author JSVS
*/
public class Registeration {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}

}

Loading