Original Post
Just wondering if anyone knew why the program below does not work as it should. What is happening is the computer is prompting for the first number to be entered as it should but it is not requested a number be entered for the second prompt and then coming out with some totally bizzare answer. I have tried debugging but that does not shed any light on the situation.
import java.io.*;
public class Class1
{
public static void main (String [] args)
throws IOException
{
int num1, num2, sum;
System.out.println ("Input a number: ");
num1 = System.in.read();
System.out.println ("Input another number: ");
num2 = System.in.read();
sum = num1 + num2;
System.out.println ("The total is " + sum );
}
}
This is an example I have been given from the course I am doing. I have had to change the following lines from the example I was given,
num1 = Course_io.readInt();
num2 = Course_io.readInt();
To the ones you see in the code above.
Help appreciated as I am a Java newbie as is probably very obvious