Home  >  Forum  >  Core Java
Post New Query

Reading Data from Keyboard in Java


joined on
March 15,2013
Asked on November 08,2013
plz give me any basic example..
joined on
October 12,2013
Replied on November 08,2013

See the below example to clear your doubt by using program.
import java.io.DataInputStream;

public class Reading {

       public static void main(String[] args) {

              DataInputStream in= newDataInputStream(System.in);

              intintNumber = 0;

              floatfloatNumber = 0.0f;

              try{

                     System.out.println("Enter an Integer: ");

                     intNumber = Integer.parseInt (in.readLine());

                     System.out.println("Enter a float number: ");

                     floatNumber = Float.valueOf(in.readLine()) .floatValue();
              }

              catch (Exception e){

                     System.out.println("intNumber = " + intNumber);

                     System.out.println("floatNumber = " + floatNumber);
              }
       }
}

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us