import java.util.Scanner;
public class SwitchCase {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String ch="NULL";
do
{
System.out.println("Enter your choice:");
String str=sc.next();
switch(str)
{
case "Add":
{
System.out.println("Enter 2 nos:");
int a=sc.nextInt();
int b=sc.nextInt();
int c=a+b;
System.out.println("Adiition is:"+c);
break;
}
case "Sub":
{
System.out.println("Enter 2 nos:");
int a1=sc.nextInt();
int a2=sc.nextInt();
int a3=a1-a2;
System.out.println("Sub is:"+a3);
break;
}
case "Multiply":
{
System.out.println("Enter 2 nos:");
int a1=sc.nextInt();
int a2=sc.nextInt();
int a3=a1*a2;
System.out.println("Sub is:"+a3);
break;
}
case "Divide":
{
System.out.println("Enter 2 nos:");
int a1=sc.nextInt();
int a2=sc.nextInt();
int a3=a1/a2;
System.out.println("Sub is:"+a3);
break;
}
case "Fib":
{
System.out.println("Enter the range:");
int n=sc.nextInt();
if (n == 0)
{
System.out.println("0");
}
else if (n == 1)
{
System.out.println("0 1");
}
else
{
System.out.print("0 1 ");
int a = 0;
int b = 1;
for (int i = 1; i < n; i++)
{
int nextNumber = a + b;
System.out.print(nextNumber + " ");
a = b;
b = nextNumber;
}
}
}
}
System.out.println("Do you want to continue? y or n");
ch=sc.next();
} while(ch=="y");
}
}
After the while loop,when "y" is entered by user,it should ask "Do you want to continue" but the same does not happen.I debugged the code,it runs fine till "Do you want to continue?" But after that :
source not found error comes, when debugged in eclipse