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



Home Answers Viewqa Java-Beginners please give me an idea to develop a program for this question?

Have Programming Question? Ask it here!
 
 
 


Balraju
please give me an idea to develop a program for this question?
1 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners


How to enter a text or number from keyboard without using InputStreamReader method in java?


Advertisement
View Answers

May 11, 2012 at 3:48 PM


Java Input values using Scanner Class

You can use Scanner class to input text or integer or double value. This class is having several different method to input string value, integer value, double value, float value etc.

import java.util.*;

class InputUsingScannerClass
{
    public static void main(String[]args){
    Scanner input=new Scanner(System.in);
    System.out.println("Enter string:");
    String str=input.nextLine();

    System.out.println("Enter integer:");
    int num1=input.nextInt();

    System.out.println("Enter double value:");
    double num2=input.nextDouble();

    System.out.println("Enter long value:");
    long num3=input.nextLong();
    System.out.println();
    System.out.println("Input Values: ");


    System.out.println(str);
    System.out.println(num1);
    System.out.println(num2);
    System.out.println(num3);

}

}


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com