0

Arrays - Fixing the Calendar

Your calendar program should output all the days of week, but it has errors. Change the code so that the program prints the days. Existing code: public class Main { public static void main(String[] args) { int[] days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; for (int i = 0; i < 7; i++) { System.out.println(days[i]); } } } I tried changing the square brackets to curly brackets for Monday etc but it doesn’t work. Please help.

7th Jun 2021, 1:46 PM
Chin Eu
Chin Eu - avatar
4 Answers
+ 1
Chin Eu Syntax for declaring array: int[] arr = { }; As Monday, Tuesday....are string so you have to declare string array not int array. String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; for (int i = 0; i < 7; i++) { System.out.println(days[i]); }
7th Jun 2021, 3:55 PM
A͢J
A͢J - avatar
+ 5
String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
7th Jun 2021, 3:40 PM
Avinesh
Avinesh - avatar
0
Thanks a lot Avinesh and Ajanant !
7th Jun 2021, 10:32 PM
Chin Eu
Chin Eu - avatar
0
public class Main { public static void main(String[] args) { String [] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; for (int i = 0; i < 7; i++) { System.out.println(days[i]); } } }
20th Sep 2022, 12:56 PM
GAUTAM SHARMA
GAUTAM SHARMA - avatar