/home/caleb/ASDV-Java/Assignments/lab11_ForLoop_CalebFontenot/src/lab11_forloop_calebfontenot/MenuDoWhile.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package lab11_forloop_calebfontenot;
import java.util.Scanner;
@author
public class MenuDoWhile {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("\nQ/q: to quit");
System.out.println("1: to calculate the square of a number");
System.out.println("2: to calculate the square root of a number");
String s = scan.next();
do
{
if (s.charAt(0) == '1' || s.charAt(0) == '2') {
System.out.println("enter the number:");
double number = scan.nextDouble();
System.out.println((s.charAt(0) == '1')
? "the square : " + (number * number)
: "the square root : " + Math.pow(number, 0.5));
} else if (s.charAt(0) != 'Q' && s.charAt(0) != 'q') {
System.out.println("invalid character");
}
System.out.println("\nQ/q: to quit");
System.out.println("1: to calculate the square of a number");
System.out.println("2: to calculate the square root of a number");
s = scan.next();
} while (s.charAt(0) != 'Q' && s.charAt(0) != 'q');
}
}