+ 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
7 Answers
+ 3
It works! just give two inputs at separate line ...
John
Jane
<Hit submit button>
+ 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.
+ 1
Ipang but why it's showing error for me
+ 1
I don't know bro ...
I run the code, gave it two inputs, and it works ...
+ 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
+ 1
Okay no problem đ