Credits

Sunday, March 1, 2009

Stream Inputs in Java

The Java program below can be modified to accept numbers of float or characters. Simply modify the code to produce the required output.



[+/-] show/hide



/* Keyboard input *using BUfferedREader/InputStreamReader*/

import java.io.*;
public class KeyboardInput{
publi static void main(string args[])
throws Exception{

InputStreamReader i = new InputStreamReader(System.in);
BufferedREader bufread=new BufferedReader( i );
System.out.print("Input a digit: ");
String digit=bufread.readLine();
int x = Integer.parseInt(digit) + 3;
System.out.println("Your input is "+digit);
System.out.println("Result is "+x);
}}

AddThis