+ 1

String and Integer

How can I get a string data and integer data in just a single input? For example: System.out.println("Enter your street address? ") String st_address = user_input.next(); In Python is used the "raw_input" which store exactly what was entered, how can I do that in Java programming language?

20th Nov 2016, 1:31 AM
VctEspiritu
VctEspiritu - avatar
1 Resposta
+ 3
Use below code import java.util.*; public class Program { public static void main(String[] args) { int ints; String str; Scanner s = new Scanner(System.in); System.out.println("Please enter integer and string by separating them with space."); String userInputs[] = s.nextLine().split(" "); ints = new Integer(userInputs[0]); str = new String(userInputs[1]); System.out.println("You have entered \n Integer:- " + ints + "\n String:- " + str); s.close(); } }
20th Nov 2016, 3:35 AM
Aditya kumar pandey
Aditya kumar pandey - avatar