我是 Java 编程语言的新手。我一直在while
用 s 练习循环语句,String
但我似乎无法正确编写此代码。我一直收到错误:
变量选择可能尚未初始化
import java.util.Scanner;
public class Test {
public static void main(String args []) {
Scanner sc=new Scanner(System.in);
int a, b,c, diff, prod, q, choice;
String name;
String choose;
System.out.print("Enter Name Please: \t");
name = sc.next();
System.out.println("WELCOME " + name);
System.out.println("");
while (choose == "Y");
{
System.out.println("1. Addition \t2. Subtraction \t3. Multiplication \t4. Division");
System.out.println("Please Choose a number: \t");
choice = sc.nextInt();
switch (choice)
{
case 1:
System.out.println("Thank You "+name+", you have chosen ADDITION");
System.out.print("\nPlease Enter the first number: \t");
a = sc.nextInt();
System.out.print("\nPlease Enter the Second number: \t");
b = sc.nextInt();
c = a + b;
System.out.println("\nYou have chosen "+a+ " as your first number, we will add it to "+b+" your second number.");
System.out.println("\nThe answer is "+c);
System.out.println("\nWould you like to choose again? Y/N: \t");
choose = sc.next();
break;