This program will solve the numbers that you will input but I want it to show ERROR if I will input some letters. Thanks for helping
This is my code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class jedz
{
public static void main (String args[])
{
BufferedReader dataln = new BufferedReader(new InputStreamReader(System.in));
int a, b, c;
String num1 =" ";
String num2 =" ";
System.out.print("Enter FN: ");
try {
num1 = dataln.readLine();
}
catch (IOException e)
{
System.out.println("Error");
}
a = Integer.parseInt(num1);
System.out.print("Enter SN: ");
try
{
num2 = dataln.readLine();
}
catch (IOException e)
{
System.out.println("Error");
}
b = Integer.parseInt(num2);
c = a + b;
System.out.print("The answer is "+ c) ;
}
}
This is the output when I put some letters.
D:\>java jedz
Enter FN: s
Exception in thread "main" java.lang.NumberFormatException: For input string: "s "
at java.lang.NumberFormatException.forInputString(NumberFormatException. java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at jedz.main(jedz.java:21)