Friday, April 3, 2009

Goldilocks - program to check the temperature

import java.io.Console;
import java.io.IOException;

class Goldilocks
{
public static void main(String[] args) throws IOException
{
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
String portemp = c.readLine("Enter the temperature of some porridge in degree centigrade: ");
int temp =(int)Float.parseFloat(portemp);
if (temp>40)
System.out.println("Too hot");
else if(temp<40)
System.out.println("Too cold");
else
System.out.println("just right ");
}
}

No comments: