Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


chandru
Quries
1 Answer(s)      2 years and 8 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)


Advertisement
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 Tutorials/Questions & Answers:
sql quries
sql quries  i want basic sql quries please provide
Advertisements
uploading image in the form
they logged into the screen. Im using Orcale database(sql quries to check
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email
Advertisements
 

 

 

DMCA.com