In: Computer Science
QUESTION 11
In util package,
public class Example {
public static void showMessage( String s ){ ....... } public static int getInt( String prompt ){ ....... } } Using these method you see above to create a main method in your class called MyExam in the different package to get input and output. The output will tell the user what number is entered. If you entered a 5, the output will be: "The number you entered is 5.".
QUESTION 12
Create a method using loop and if-else to identify 5 numbers, print out which number is odd and which number is even. You will use the following method to gereratethose 5 numbers: int randomNum = (int)(Math.random() * 101); // generate number between 0 to 100. The operator you will use is "%", this operator will return the division remainder, for example: 134%5 = 4. The output should be like: "3 is an odd number.", "24 is an even number." The name of the method will be isOdd.
Answer 11:
public class MyProgram {
public static void main(String[] args) {
Example ex = new Example();
int n=ex.getInt("Enter integer:
");
ex.showMessage("The number you
entered is "+n+".");
}
}
Answer 12:
public class MyProgram{
public static void main(String[] args) {
for(int i=0;i<5;i++) {
int randomNum = (int)(Math.random() * 101);
if(randomNum % 2 == 0)
System.out.println(randomNum+" is an even number");
else
System.out.println(randomNum+" is an odd number");
}
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME