+ 2

Question in java

import java.util.*; public class Program { public static void main(String[] args) { String[] a = new String[2]; System.out.println("Enter your array :"); Scanner sc =new Scanner(System.in); for(int i=0;i<2;i++){ a[i]=sc.nextLine(); } // Arrays.sort(a); System.out.println("store your array"); for(String b:a){ System.out.println(b); } } } // unable to store more then 1 value why?? I'm getting error if I store more then 1 string If anyone know the answer pls solve

15th Oct 2021, 8:30 AM
Musaif
7 Answers
+ 3
It works! just give two inputs at separate line ... John Jane <Hit submit button>
15th Oct 2021, 8:45 AM
Ipang
+ 2
Musaif If you want to take in single line then just write next() instead of nextLine() but in this case if you give input like this: ab cd efg then only ab and cd will be consider.
15th Oct 2021, 9:18 AM
A͢J
A͢J - avatar
+ 1
Ipang but why it's showing error for me
15th Oct 2021, 9:04 AM
Musaif
+ 1
I don't know bro ... I run the code, gave it two inputs, and it works ...
15th Oct 2021, 9:06 AM
Ipang
+ 1
Seperate lines Ooh! No from that time I'm giving input in a single line that's why I'm getting errors 😅😅😅 thank you sooo much Ipang
15th Oct 2021, 9:07 AM
Musaif
+ 1
Okay no problem 👌
15th Oct 2021, 9:07 AM
Ipang