Friday, August 26, 2011

InputStream example in java


//Enter a number and find out is your given number is +Ve or -Ve or ZERO.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputStreamExample
{
public static void main(String args[]) throws IOException
{
String s;
int n;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter value of n =");
s = br.readLine();
n = Integer.valueOf(s).intValue();

if (n > 0)
System.out.println("("+n+") is a +Ve number");
else if (n<0)
System.out.println("("+n+") is a -Ve number");
else
System.out.println("Value you entered is ZERO");
}
}


Output 1=>
Enter value of n =12
(12) is a +Ve number


Output 2=>
Enter value of n =-15
(-15) is a -Ve number

Output 3=>
Enter value of n =0
Value you entered is ZERO

No comments:

Post a Comment