I'm trying to make a program that will make string s1 equal to certain text depending on the hours variable. The problem Is when I run the program s1 isn't found. I'm just starting out with java so I'm not sure if this is really inefficient or if it's something simple I'm missing.
Thanks in advance, - Tile124
Code:
public class Main {
public static void main(String[] args) {
// String Change Test
int[] arr;
arr = new int[2];
arr[0] = 1;
boolean b1 = arr[0] > 1;
boolean b2 = arr[0] < 1;
boolean b4 = 0 > arr[0];
boolean b3 = b4 && b2;
boolean b5 = b1 || b3;
if (b5) {
String s1 = "You have played for " + arr[0] + " hours!";
}
else if (arr[0] == 1) {
String s1 = "You have played for 1 hour!";
}
else if (arr[0] == 5) {
String s1 = "You have not played at all!";
}
else {
String s1 = "Memory Error in arr[0], Are the hours negative? Is it there?";
}
System.out.print (s1);
}
}
Aucun commentaire:
Enregistrer un commentaire