
Write a java program to accept different types of inputs in a line at time from the keyboard(like name,age,salary,gender) just like one can do using scanf() in c (using String tokenizer).

import java.io.*;
import java.util.*;
class InputValues{
public static void main( String [] args )throws Exception{
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
System.out.println("Enter string that contains name, age, salary and gender separated by comma(,): ");
String input = br.readLine();
StringTokenizer st = new StringTokenizer(input, ",");
String name=st.nextToken();
int age=Integer.parseInt(st.nextToken());
int salary=Integer.parseInt(st.nextToken());
String gender=st.nextToken();
System.out.println();
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Salary: "+salary);
System.out.println("Gender: "+gender);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.