Thursday, 8 August 2013

Simple Java Program Strange Output

Simple Java Program Strange Output

This is my program...
import java.lang.Math;
class SquareRoot
{
public static void main(String args[])
{
try
{
System.out.println("Enter A Number To Find its Square Root");
System.out.flush();
double x = (double) System.in.read();
double y;
y = Math.sqrt(x);
System.out.println("Square Root of " + x + " is " + y);
}
catch (Exception e)
{
System.out.println("I/O Error! Humein Maaf Kar Do Bhaaya");
}
}
}
If I enter 75 as input it shows.. Square Root of 55.0 is <55's square root>
On entering 23 it shows Square Root of 50.0. Where am I wrong? No problems
in compilation.
I am using DrJava IDE. JDK 7u25 Compiler. Windows 7 32 bit.

No comments:

Post a Comment