How to take n number of strings from user

String str=s.nextLine();
int decimal=Integer.parseInt(str,2);
System.out.println(decimal);

Hi ritu, you can make an array of strings and then take inout from user.

we have not study arrays now .what to do in this case

Hi ritu

You can use loops for that.

Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
while(n > 0){
String str = s.nextLine();
int decimal=Integer.parseInt(str,2);
System.out.println(decimal);
n–;
}

This code will now take as many inputs as mentioned in the integer n.

Scanner s = new Scanner(System.in); int a=s.nextInt(); int n = s.nextInt(); while(n > 0){ String str = s.nextLine(); int decimal=Integer.parseInt(str,2); System.out.println(decimal); n–; }

not able to take multiple string inputs please help

Hi ritu

It’s n - - in the end. Did you do that? If yes, then send me the error you are getting.

Hi Ritu,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.