Sei sulla pagina 1di 8

1.

Write a program which accepts days as integer and display total number of years,
months and days in it. Assume 1 Year = 365 Days

Program:
import java.util.Scanner;

public class Year


{

public static void main(String[] args)


{
Scanner inp=new Scanner(System.in);
int number,year,month,day,days;
System.out.println("Enter the number of days ");
number=inp.nextInt();
year=number/365;
day=number%365;
month=day/30;
days=day%30;
System.out.println(year +" year " + month +" month "+days +" days " );
}

}
Output:

2. Given 2 int values, return true if both the numbers are in the range 30..40 inclusive, or in
the range 40..50 inclusive
Program:
import java.util.Scanner;

public class Check {

public static void main(String[] args)


{
Scanner inp=new Scanner(System.in);
int num1,num2;
System.out.println("Enter the number 1 and number 2");
num1=inp.nextInt();
num2=inp.nextInt();
if((num1>=30)&&(num2<=40))
System.out.println("true");
else if ((num1>=40)&&(num2<=50))
System.out.println("True");
else
System.out.println("False");
}

}
Output:

3. Given 2 int values and Boolean flag (true/false), If flag is true: return true if exactly one
is negative and one is positive, false otherwise If flag is false: return true if either both are
positive or both are negative, false otherwise
Program:
import java.util.Scanner;

public class Truefalse


{
public static void main(String[] args)
{
Scanner inp=new Scanner(System.in);
int num1, num2;
Boolean flag;
System.out.println("Enter the number 1 and number 2");
num1=inp.nextInt();
num2=inp.nextInt();
System.out.println("Enter the flag value ");
flag=inp.nextBoolean();
if((num1>0)&&(num2<0)&&flag==true)
System.out.println( "true");
else if((num1<0)&&(num2>0)&&flag==true)
System.out.println("true");
else if((num1>=0)&&(num2>=0)&&flag==true)
System.out.println( "true");
else if((num1<0)&&(num2>0)&&flag==false)
System.out.println("false");
else if((num1<0)&&(num2<0)&&flag==true)
System.out.println("false");
else if((num1>=0)&&(num2>=0)&&flag==false)
System.out.println( "true");
else if((num1<0)&&(num2<0)&&flag==false)
System.out.println("true");
else if((num1>0)&&(num2<0)&&flag==false)
System.out.println("false");

}
Output:

7. Accept two numbers and perform the following operations simultaneously 1. Print prime
numbers between them. 2. Print all numbers between them. 3. List all the multiples of two
between them

Program:
import java.util.Scanner;

public class Operation extends Thread


{

public void run()


{
Scanner inp=new Scanner(System.in);
int first,last,i,count=0,num;
System.out.println("Accept the first and the last number:");
first=inp.nextInt();
last=inp.nextInt();
System.out.println("Prime numbers");
for(num=first;num<last;num++)
{
count=0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0)
{
System.out.println(num + " ");
}

}
System.out.println("NUmbers between them");
for(num=first;num<last;num++)
{
System.out.println(num);
}
System.out.println("Numbers multiple by 2");
for(num=first;num<last;num++)
{
if(num%2==0)
{
System.out.println(num);
}
}
}
public static void main(String[] args)
{
Operation t1=new Operation();
t1.start();

}
}

Output:
6. Crete an employee class with empno, first name, lastname, Date of Birth, Basic Salary,
Date of Joining, PAN Card and Aadhar card details. Include methods required to accept
and print the data. While printing the data along with the details, information about the
experience in the current company needs to be printed. Required Validations 1. Employee
must be of above 18 years 2. Date of joining should be above Date of Birth 3. Pan Card
should be of correct format 4. Aadhar card should be of 12 digits.

Program:

import java.util.Date;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Employee


{
String first,last,pancard;
int dob,joining;
String aadhar;
int age;
static int cnt=00;
Employee()
{
Scanner inp=new Scanner(System.in);
System.out.println("Enter the first name:");
first=inp.nextLine();
System.out.println("Enter the last name :");
last=inp.nextLine();
System.out.println("Enter the date of birth :");
dob=inp.nextInt();
System.out.println("Enter the joining date :");
joining=inp.nextInt();
inp.nextLine();
System.out.println("Enter the aadhar card number :");
aadhar=inp.nextLine();
System.out.println("Enter the pan card number :");
pancard=inp.nextLine();
cnt++;

String cd1=first.substring(0,2);
String cd2=last.substring(2,4);
String str=cd1.concat(cd2);
System.out.println("code: "+str+"00"+cnt);

public void checkage()


{
age=joining-dob;
if(age>=18)
System.out.println("eligible age");
else
System.out.println("not a eligible age ");
}
public void checkdate()
{
if(joining>dob)
System.out.println("eligible");
else
System.out.println("not eligible");
}
public boolean checkpan()
{
Pattern pat = Pattern.compile("[a-z]{5}[0-9]{4}[a-z]{1}");

Matcher mat = pat.matcher(pancard);


return(mat.matches());

}
public void checkaadhar()
{
int num=aadhar.length();
if(num==12)
{
System.out.println("valid aadhar number");
}
else
{
System.out.println("invalid aadhar");
}
}

public static void main(String[] args)


{
Employee obj=new Employee();
obj.checkage();
obj.checkdate();
obj.checkaadhar();
System.out.println(obj.checkpan());

}
Output:

Potrebbero piacerti anche