- 1
Why is my code not working?
4 Answers
+ 4
The code works.
What are you trying to do?
+ 4
No need for a loop to improve your code and avoid the switch statement... simply do:
class Paturday {
public static void main(String[]args) {
int day=2;
String[] week = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
System.out.println(week[day-1]);
}
}
(indexes of arrays start at zero, so we decremente 'day' value as your switch was starting to value 1 for 'monday" ;)
0
lmao i just changed it, but can u copy the whole code but delete all the day++ and day-- and show me how a while loop would be worked into the code please thank you
0
add a while loop to the code