Computer Project
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
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);
Variable listing
Variable
a