+ 2

Java

import java.util.Scanner; public class input { public static void main(String[] args) { System.out.println("hello"); Scanner sr = new Scanner(System.in); System.out.println("enter your value1"); int a = sr.nextInt(); System.out.println("enter yourvalue2"); int b = sr.nextInt(); int sum= a+b; System.out.println(sum); } } Why I'm getting error???

29th Aug 2021, 11:41 AM
Musaif
8 Answers
+ 3
I work's fine for me what error are u getting
29th Aug 2021, 11:45 AM
Pariket Thakur
Pariket Thakur - avatar
29th Aug 2021, 12:54 PM
Pariket Thakur
Pariket Thakur - avatar
+ 2
int a, b; try { a = sr.nextInt(); } catch (Exception e) { a = 0; } try { b = sr.nextInt(); } catch (Exception e) { b = 0; } System.out.println("enter your value 1 : " + a); System.out.println("enter your value 2 : " + b);
29th Aug 2021, 1:28 PM
SoloProg
SoloProg - avatar
+ 2
it is work import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println("hello"); Scanner sr = new Scanner(System.in); System.out.println("enter your value1"); int a = sr.nextInt(); System.out.println("enter yourvalue2"); int b = sr.nextInt(); int sum= a+b; System.out.println(sum); } }
30th Aug 2021, 7:17 PM
Qutaba Qais Mahmood
Qutaba Qais  Mahmood - avatar
29th Aug 2021, 2:46 PM
SoloProg
SoloProg - avatar
0
But for me it's showing scanner error
29th Aug 2021, 12:14 PM
Musaif
0
Thank you sooooo much guys
29th Aug 2021, 2:05 PM
Musaif