Help me, please. Why there is no value for s2 variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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