chandru
Quries
1 Answer(s)      a year and 10 months ago
Posted in : Java Beginners

Java Program To accept different types of inputs in aline at atime from the keyboard (like name,age,salary,gender) just like one can do using scanf() in c(using StringTokenizer)

View Answers

August 5, 2011 at 12:30 PM


import java.util.*;
class AcceptData 
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter Name: ");
        String name=input.next();
        System.out.print("Enter Age: ");
        int age=input.nextInt();
        System.out.print("Enter Salary: ");
        int sal=input.nextInt();
        System.out.print("Enter Gender: ");
        String gender=input.next();
        String str = "Name="+name+";Age=" +age+";Salary="+sal+";Gender="+gender+";"; 
        StringTokenizer st = new StringTokenizer(str, "=;");
        while(st.hasMoreTokens()) {
        String key = st.nextToken();
        String val = st.nextToken();
        System.out.println(key + ":\t" + val);
        } 
    }
}









Related Pages:
sql quries
sql quries  i want basic sql quries please provide
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email

Ask Questions?

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.