Answer to Question #268906 in Java | JSP | JSF for Sara

Question #268906

5. Prompt the user to enter y or n. If the user enters an invalid character, keep re-prompting until a value character is entered. Use a while loop.

 

6. Redo

for(int a=1; a<=3; a++)

  for(int b=2; b<5; b++)

   out.print(a+b + " ");

with a do-while loop.

 

7. Write a method checkeven which receives 3 integer variables and prints YES if all three numbers are even. Otherwise, the method prints NO. ("receives" means that these values will be passed to the method as parameters)


8. Write the statements to read in three numbers and call the checkeven method.


9. Write another version of the checkeven method. This version receives 3 integer variables and returns true if all three numbers are even. Otherwise, the method returns false.


10. Write the statements to read in three numbers and call the new version of the checkeven method. Then print YES if all three numbers were even, or print NO if they were not all even.



1
Expert's answer
2021-11-20T06:43:10-0500
import java.util.Scanner;
public class Main
{
    static void CheckChar(){
        Scanner input=new Scanner(System.in);
        System.out.println("enter a character: ");
		char n = input.next().charAt(0); 
	   char	m='n';
	   char y='y';
		    if(n==m||n==y){
		    System.out.println("You entered: "+n);
		    }
		   else{
		        System.out.println("enter a character: ");
		        n = input.next().charAt(0); 
		    if(n==m||n==y){
		    System.out.println("You entered: "+n);
		    }
		    else{
		        System.out.println("enter a character: ");
		        n = input.next().charAt(0); 
		    if(n==m||n==y){
		    System.out.println("You entered: "+n);
		    }
		    else{
		        System.out.println("enter a character: ");
		        n = input.next().charAt(0); 
		    if(n==m||n==y){
		    System.out.println("You entered: "+n);
		    }
		    else{
		        System.out.println("enter a character: ");
		        n = input.next().charAt(0); 
		    if(n==m||n==y){
		    System.out.println("You entered: "+n);
		    }
		    }
    }}}}
    static void CheckEven(){
        Scanner input=new Scanner(System.in);
        System.out.println("Enter the 3 numbers: ");
         int num1=input.nextInt();
		    int num2=input.nextInt();
		    int num3=input.nextInt();
		    if(num1%2==0&&num2%2==0&&num3%2==0){
		        System.out.println("Yes");
		    }
		    else {
		        System.out.println("No");
		    }
    }
    static void redo(){
        int a=1;
        do{
        for(a=1; a<=3; a++)


  for(int b=2; b<5; b++)


   System.out.print(a+b + " ");}
   while(a>100);
    }
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
		CheckChar();
		   CheckEven();
		   redo();
		}}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS