Home  >  Forum  >  Core Java
Post New Query

Reading Data from Keyboard in Java



Asked on November 08, 2013
plz give me any basic example..



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




©2019 concretepage.com | Privacy Policy | Contact Us