Sunday, April 18, 2010

user input in java

The program will ask the user to input name, address and the program will show what they input.
we use here the namespace which is the util.scanner.

User input in java using string;

name of java file: javainput

Sample program:

import java.util.scanner;
public class javainput
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);

//declaration
String name,address;
System.out.println("Enter your name:");
name=input.next();

System.out.println("Enter your name:");
address=input.next();

//displaying the result
System.out.print("Your Name:" + name);
System.out.print("Your Name:" + add);
}
}

No comments:

Post a Comment