You are on page 1of 9

ASSIGNMENT ONE

1. Write a program that will read a number from the user.  The number will be tested and:

a. if the number is exactly divisible by 2 it will print "the number is even"


b. if the number is exactly divisible by 3 it will print "the number is divisible by 3"
c. if the number is exactly divisible by 5 it will print "the number multiple of 5"
d. Otherwise it will print: this number is not divisible either by 2, 3 or 5.
e. Make sure that you validate everything.

//Java progam to test whether n is divisible by 2,3 and 5

Public class divisibilityTest{

Public static void main(String[] args)

{ Scanner sc = new Scanner(System.in);

System.out.print(“Enter any number:”)

Int num = sc.nxtInt()

If (num % 2== 0)

{System.out.println( num + “the number is even”}

elseIf

(num % 3== 0)

{System.out.println( num + “is divisible by 3”}

elseIf

(num % 5==0)

{System.out.println (num + “is divisible by 5”}

else

{System.out.println (num + “this number is not divisible by either 2,3 or 5”);

}
}

//Java progam to test whether n is divisible by 2,3 and 5

Public class divisibilityTest{

Public static void main(String[] args)

{ Scanner sc = new Scanner(System.in);

System.out.print(“Enter any number:”)

Int num = sc.nxtInt()

If (num % 2== 0)

{System.out.println( num + “the number is even”}

elseIf

(num % 3== 0)

{System.out.println( num + “is divisible by 3”}

elseIf

(num % 5==0)

{System.out.println (num + “is divisible by 5”}

else

{System.out.println (num + “this number is not divisible by either 2,3 or 5”);

}
//Java progam to test whether n is divisible by 2,3 and 5

Public class divisibilityTest{

Public static void main(String[] args)

{ Scanner sc = new Scanner(System.in);

System.out.print(“Enter any number:”)

Int num = sc.nxtInt()

If (num % 2== 0)

{System.out.println( num + “the number is even”}

elseIf

(num % 3== 0)

{System.out.println( num + “is divisible by 3”}

elseIf

(num % 5==0)

{System.out.println (num + “is divisible by 5”}

else

{System.out.println (num + “this number is not divisible by either 2,3 or 5”);

}
import java.util.Scanner;

Public class divisibilityTest{

Public static void main(String[] args)

{ Scanner sc = new Scanner(System.in);

System.out.print(“Enter any number:”);

Int num = sc.nextInt();

If (num % 2== 0)

{System.out.println( “the number is even”)};

else if

(num % 3== 0)

{System.out.println("the number is divisible by 3”) };

else if

(num % 5==0)

{System.out.println ("the number is a multiple of 5”)}

else

{System.out.println (“this number is not divisible by either 2,3 or 5”);

}
package mycompany.assignmentjava;

import java.util.Scanner;

public class divisibilityTest{

public static void main(String[] args){

Scanner sc = new Scanner(System.in);

System.out.print("Enter any number");

int num = sc.nextInt();

if (num % 2== 0)

System.out.println("The number is even");

if

(num % 3== 0)

System.out.println("The number is divisible by 3");

if

(num % 5==0)

System.out.println ("The number is a multiple of 5");

else

System.out.println (“ number is not divisible by either 2,3 or 5”);

}
package mycompany.assignmentjava;

import java.util.Scanner;

public class divisibilityTest{

public static void main(String[] args){ //after main there is no semi-colon

Scanner sc = new Scanner(System.in);

System.out.print("Enter any number");

int num = sc.nextInt();

if (num % 2== 0)

System.out.println("The number is even");

if

(num % 3== 0)

System.out.println("The number is divisible by 3");

if

(num % 5==0)

System.out.println ("The number is a multiple of 5");

else

System.out.println ("This number is not divisible by either 2,3 or 5");

}
import java.util.Scanner;
public class divisibilityTest{
public static void main(String[] args){ //after main there is no semi-
colon

Scanner sc = new Scanner(System.in);


System.out.print("Enter any number");
int num = sc.nextInt();
if (num % 2== 0)
System.out.println("The number is even");
if
(num % 3== 0)
System.out.println("\nThe number is divisible by 3");
if
(num % 5==0)
System.out.println ("\nThe number is a multiple of 5");
else if
( (num % 2== 0) && (num % 3 == 0) && (num % 5==0) )
System.out.println ("This number is not divisible by either 2,3 or 5");
}
}

You might also like