0

Java input problem

Hi! Here's my code: public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a; int b; System.out.print("Give first number: "); a = sc.nextInt(); System.out.print("Give second number: "); b = sc.nextInt(); int sum = a + b; if (a <=0) { System.out.println("Must be positive and above zero"); } else if ( b <= 0) { System.out.println("Must be positive and above"); } else{ System.out.print("The sum of first and second number is: "+sum); System.out.println(); } } } How to correct to stop immediately after the first number is <= 0 without asking for the second number??

20th Feb 2019, 6:01 PM
Tibor Tóth
Tibor Tóth - avatar
3 Réponses
+ 2
You running in Sololearn or external?
20th Feb 2019, 6:05 PM
Maneren
Maneren - avatar
20th Feb 2019, 6:20 PM
Maneren
Maneren - avatar
0
Thanks! Running external and works!
20th Feb 2019, 6:28 PM
Tibor Tóth
Tibor Tóth - avatar