Randomly generate an integer number in range [1, 999], (a) Check if this number is even or odd, display message “[number] is an even number” or “[number] is an odd number”. For example, if the number is 10, display message “10 is an even number”. (b) Check if this number is divisible by 7 and 11. Display message showing result (c) Check if this number is divisible by 9 or 13. Display message showing result (d) Check if this number is divisible by 5 or 12, but not both. Display result
In Java Please
Required program in JAVA -->
import java.util.Random;
public class Main{
public static void main(String args[])
{
Random rand = new Random();
int number = rand.nextInt(1000);
//randomly generate a value between 0 to 1000
System.out.println("Random Number:
"+number); // show the randomly generated number
if(number%2==0){ // if number%2==0
means if number is even
System.out.println(number+" is even
number"); // print number is even
}
else{ // number is odd
System.out.println(number+" is odd
number"); //print number is odd
}
if(number%7==0 &&
number%11==0){ //if number is divisible by 7 and 11
System.out.println("Number is
divisible by 7 and(&&) 11"); //print divisible
}
else{ // if number is not divisible
by 7 and 11
System.out.println("Number is not
divisible by 7 and(&&) 11"); //print not divisible
}
if(number%9==0 || number%13==0){
//if number is divisible by 9 or 13
System.out.println("Number is
divisible by 9 or(||) 13"); //print divisible
}
else{ //if number is not divisible
by 9 or 13
System.out.println("Number is not
divisible by 9 or(||) 13"); //print not divisible
}
if(number%5==0 || number%12==0){
//if number is divisible by 5 or 12
System.out.println("Number is
divisible by 5 or(||) 12"); //print divisible
}
else{ // if number is not divisible
by 5 or 12
System.out.println("Number is not
divisible by 5 or(||) 12"); //print not divisible
}
}
}
Get Answers For Free
Most questions answered within 1 hours.