+ 5

Help me, please. Why there is no value for s2 variable?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a; String s1, s2; s1=sc.nextLine(); a=sc.nextInt(); s2=sc.nextLine(); System.out.println("a=" + a); System.out.println("s1="+s1); System.out.println("s2="+s2); } }

12th May 2020, 5:33 PM
ROSA
ROSA - avatar
5 Réponses
+ 5
s1=sc.nextLine(); a=sc.nextInt(); sc.nextLine(); s2=sc.nextLine(); Check Ipang's answer to understand why👇 https://www.sololearn.com/Discuss/2099456/?ref=app ROSA Sorry😅.👆
12th May 2020, 5:45 PM
Kevin ★
+ 4
Just do this : s1 = sc.nextLine(); s2 = sc.nextLine(); a = sc.nextInt();
12th May 2020, 5:36 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 4
How to view lpang's answer?
12th May 2020, 5:48 PM
ROSA
ROSA - avatar
+ 4
Thanks a lot, it's working
12th May 2020, 5:54 PM
ROSA
ROSA - avatar
+ 2
Thank you, but I need that order of variable declaration
12th May 2020, 5:43 PM
ROSA
ROSA - avatar