I am new to java programming language. I've been practicing the while
loop statement with String
s and I can't seem to get this code right. I've been getting error:
variable choose might not have been initialized
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;