Program to Read text entered by use in console using java.util.Scanner








Program to Read text entered by use in consoler using BufferedReader's readLine() method in java file IO >





import java.io.IOException;
import java.util.Scanner;
/** JavaMadeSoEasy.com */
public class ReadFromUsersInputUsingScanner {
   public static void main(String[] args) throws IOException {
         
          Scanner scan = new Scanner(System.in);
         
          System.out.print("enter your name : ");
          String name = scan.next(); // //will wait for user to enter name
          System.out.println("enter your name : " + name);
          System.out.print("\nenter your age : ");
          int age = scan.nextInt();//will wait for user to enter age
          System.out.println("Your age is : " + age);
          System.out.print("\nenter your salary : ");
          double salary = scan.nextDouble();//will wait for user to enter salary
          System.out.println("Your salary is : " + salary);
          scan.close();
   }
}
/*OUTPUT
enter your name : ankit
enter your name : ankit
enter your age : 30
Your age is : 30
enter your salary : 100.00
Your salary is : 100.0

*/


RELATED LINKS>

Program to Read text entered by user in console using DataInputStream in java file IO

Read text entered by use in consoler using BufferedReader's readLine() method in java file IO

Program to Read text entered by user in console till some special character (let's say @) in java


Program to Create Directory - Single and multiple (i.e. parent and child directories) in java file IO

No comments:

Post a Comment