M
machoextreme
As you can probably guess by the title, I'm a newbie. I'm still hitting
brick walls on with really easy solutions. One of them is on the latest
excersices in my textbook. I've written and compiled my program, but I
get this error. Any help/advice would be greatly appreciated.
variable act may not have been initialized
import java.util.*;
public class activities
{
public static void main(String[] args)
{
String act;
int temp;
Scanner keyboard= new Scanner(System.in);
System.out.println("In order to decide what is the best activity at
the present time, please enter the current temperature ");
temp = keyboard.nextInt();
if (temp > 85)
act = "Swimming";
else if ((temp > 70) && (temp <= 85))
act = "Tennis";
else if ((temp > 32) && (temp <= 70))
act = "Golf";
else if ((temp > 0) && (temp <= 32))
act = "Skiing";
else if (temp <=0 )
act = "Dancing";
System.out.println("The recommened activity for the current
temperature is " );
System.out.println(act);
}
}
brick walls on with really easy solutions. One of them is on the latest
excersices in my textbook. I've written and compiled my program, but I
get this error. Any help/advice would be greatly appreciated.
variable act may not have been initialized
import java.util.*;
public class activities
{
public static void main(String[] args)
{
String act;
int temp;
Scanner keyboard= new Scanner(System.in);
System.out.println("In order to decide what is the best activity at
the present time, please enter the current temperature ");
temp = keyboard.nextInt();
if (temp > 85)
act = "Swimming";
else if ((temp > 70) && (temp <= 85))
act = "Tennis";
else if ((temp > 32) && (temp <= 70))
act = "Golf";
else if ((temp > 0) && (temp <= 32))
act = "Skiing";
else if (temp <=0 )
act = "Dancing";
System.out.println("The recommened activity for the current
temperature is " );
System.out.println(act);
}
}