10. Inside class StaticMethods, create the static method menu that displays a menu for the user to select 's' or 'c'. The method returns the character entered, ONLY when the user types 's' or 'c', otherwise prints a message and stays in a loop. Test it from main(). public static char menu() { String s = ""; do { System.out.println("type S\\s to square a number:"); System.out.println("type C\\c to cube a number:" ); S = new Scanner( System.in).next(); if ( "c".compareToIgnoreCase(s) != 0 && "s".compareToIgnoreCase(s) != 0 ) System.out.println("\tplease enter a valid character" ); } while ("c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 ); return s.charAt(0);

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 4GZ
icon
Related questions
Question
10. Inside class StaticMethods, create the static method menu that displays a menu for the user
to select 's' or 'c'. The method returns the character entered, ONLY when the user types 's'
or 'c', otherwise prints a message and stays in a loop. Test it from main().
public static char menu()
{
String s = "";
do
{
System.out.println("type S\\s to square a number:" );
System.out.println("type C\\c to cube a number:" );
S = new
Scanner( System.in).next();
if ( "c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 )
System.out.println("\tplease enter a valid character" );
}
while ("c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 );
return s.charAt (0);
}
Transcribed Image Text:10. Inside class StaticMethods, create the static method menu that displays a menu for the user to select 's' or 'c'. The method returns the character entered, ONLY when the user types 's' or 'c', otherwise prints a message and stays in a loop. Test it from main(). public static char menu() { String s = ""; do { System.out.println("type S\\s to square a number:" ); System.out.println("type C\\c to cube a number:" ); S = new Scanner( System.in).next(); if ( "c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 ) System.out.println("\tplease enter a valid character" ); } while ("c".compareToIgnoreCase(s ) != 0 && "s".compareToIgnoreCase(s) != 0 ); return s.charAt (0); }
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT