0% found this document useful (0 votes)
6 views

Computer Project

Uploaded by

soumalayapc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Computer Project

Uploaded by

soumalayapc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Computer Project

~~~~~~~~~~~~~~~~
1./*Input a number and check whether the number is divisible
by 3 as well as 5*/
import java.util.*; //Import java package
class Prog //Declare the class
{
public static void main(String args[]) //main method
{
Scanner in=new Scanner (System.in);
System.out.print(“Enter the number”);
int num=in.nextInt(); //Declare the variable and Input the
value
if (num % 3==0 && num % 5==0)
System.out.print(“Divisible by 3 and 5”);
else if (num % 3==0)
System.out.print(“Divisible by 3 but not by 5”):
else if (num % 5==0)
System.out.print(“Divisible by 5 but not by 3’);
else
System.out.print(“Neither divisible by 3 nor by 5”);
} //end of main method
} //end of class
Variable listing

Variable Datatype Input Output Function


num int To input _____ To check
variable that if a
number is
divisible
by 3 as
well as 5.

2./*Input year and check whether it is a


leap year, a century leap year or a
century year*/
import java.util.*; //Import java package
class Prog //Declare the class
{
public static void main(String args[])
//main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the year to
check: ");
int yr = in.nextInt();//Declare the
variable and Input the value
if (yr % 4 == 0 && yr % 100 != 0)
System.out.println("It is a Leap Year");
else if (yr % 400 == 0)
System.out.println("It is a Century Leap
Year");
else if (yr % 100 == 0)
System.out.println("It is a Century Year
but not a Leap Year");
else
System.out.println("It is neither a
Century Year nor a Leap Year");
}//end of main method
}//end of class
Variable listing
Variable Data Input Output Function
Type
yr int To ______ To check
input that a
vaiable year is
a leap
year or
a
century
leap
year or
century
year

3./* Input two unequal positive numbers and check whether


they are perfect square or not*/
import java.util.*; //Import java package
class prog //Declare the class
{
public static void main(String args[])//Main method
{
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = in.nextInt(); //Declare the variable a and input the
value
System.out.print("Enter second number: ");
int b = in.nextInt();//Declare the variable b and input the
value

if (a < 0 || b < 0) {
System.out.println("Square root of a negative number
can't be determined");
}
else {
double sqrtA = Math.sqrt(a);
double sqrtB = Math.sqrt(b);
double isAPerfectSq = sqrtA - Math.floor(sqrtA);
double isBPerfectSq = sqrtB - Math.floor(sqrtB);

if (isAPerfectSq == 0 && isBPerfectSq == 0) {


System.out.println("They are perfect square
numbers.");
}
else if (isAPerfectSq == 0) {
System.out.println(a + " is a perfect square
number.");
System.out.println(b + " is not a perfect square
number.");
}
else if (isBPerfectSq == 0) {
System.out.println(a + " is not a perfect square
number.");
System.out.println(b + " is a perfect square
number.");
}
else {
System.out.println("Both are not perfect square
numbers.");
}
}
}

Variable listing
Variable
a

You might also like