Input types in java

how to take input in java where i need to parse string as well as integer from one single line?
example:
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
if(…)
String str=br.readLine();
else
int x=Integer.parseInt(br.readLine());
what should I specify in if condition? or how to take both types of input?

This should work for you

Take the input using readLine on a String (normal procedure) then, You could try to split on a regular expression like (?<=\D)(?=\d)

String str = "ask1234";
String[] part = str.split("(?<=\\D)(?=\\d)");
System.out.println(part[0]);
System.out.println(part[1]);

will output

ask
1234

then parse the String to Integer in part[1] with Integer.parseInt(part[1]).

1 Like
//