- #1
Darkstar3000
- 29
- 0
I tried to write this program but the loop just won't run, am I missing something ?
Code:
import java.io.*;
import java.util.*;
public class basicswitch
{
private static void main(String [] args)throws IOException
{
int a ,b,y, x = 0;
double c = 0;
BufferedReader in;
in = new BufferedReader( new InputStreamReader( System.in ) );
while(true)
{
System.out.println("Enter the value of a: ");
a = Integer.parseInt( in.readLine() );
System.out.println("Enter the value of b: ");
b= Integer.parseInt( in.readLine() );
System.out.println("Enter 1 for addition\n2 for subtraction\n3 for multiplication\nor 4 for division");
x = Integer.parseInt( in.readLine() );
switch(x)
{
case 1:
c = a + b;
System.out.println("The sum is :"+c);
break;
case 2:
c = a - b;
System.out.println("The difference is :"+c);
break;
case 3:
c = a * b;
System.out.println("The product is :"+c);
break;
case 4:
c = (a / b);
System.out.println("The quotient is :"+c);
break;
}
System.out.println( "Press Y if you wish to enter new numbers : ");
y = in.readLine().charAt( 0 );
if((y == 'y') || (y == 'Y'))
{
System.out.println("Enter the value of a: ");
a = Integer.parseInt( in.readLine() );
System.out.println("Enter the value of b: ");
b= Integer.parseInt( in.readLine() );
continue;
}
}
}
/////////////////////////////////////////////////////////////////////////
} // End of class