Sir/Ma’am I am not able to figure out how to take input in this problem with scanner as n is not given.Please Help Me Out
Problem Right View
This is sample code for variable number of inputs.
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String input;
try{
while(!(input=s.next()).equals("")){
int x = Integer.parseInt(input);
System.out.println(x);
}
}catch(NoSuchElementException ex){
System.out.println(“Done with input”);
}
}}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.