Solution.java:23: error: ')' expected System.out.printf("The day of the week is -> %s %n%n%n", "daysOfWeek[dayOfWeek]"; ^
Question
Solution.java:23: error: ')' expected System.out.printf("The day of the week is -> %s %n%n%n", "daysOfWeek[dayOfWeek]"; ^
Solution
The error message is indicating that there is a missing closing parenthesis ')' in your System.out.printf statement.
Here is the corrected version of your code:
System.out.printf("The day of the week is -> %s %n%n%n", daysOfWeek[dayOfWeek]);
In your original code, you had an extra semicolon ';' before the closing parenthesis ')'. Also, you had "daysOfWeek[dayOfWeek]" in quotes which would print the string as is, instead of the value of the array at the index 'dayOfWeek'. In the corrected code, I removed the quotes to ensure the value at the specified index is printed.
Similar Questions
import java.util.Calendar;public class JavaDateAndTimeDaysOfWeekFinder { public static String findDay(int month, int day, int year) { System.out.println("_________________________ Java Date And Time Days Of Week Finder _________________________________"); System.out.printf("The day of the week is -> %d/%d/%d %n",day,month,year); Calendar calendar = Calendar.getInstance(); calendar.set(year, month-1, day); // note: months in Calendar are 0-based (0 = January, 1 = February, ..., 11=December) int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); String[] daysOfWeek = {"", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" }; System.out.printf("The day of the week is -> %s %n%n%n", "daysOfWeek[dayOfWeek]"; return daysOfWeek[dayOfWeek]; }}
Give the output of the following code segment-public class Main {public static void main(String[] args) {int day = 4;switch (day) {case 6:System.out.println("Today is Saturday");break;case 7:System.out.println("Today is Sunday");break;default:System.out.println("Looking forward to the Weekend");}}
What will be the output of the following program? Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 7); cal.set(Calendar.MONTH, 4); cal.set(Calendar.YEAR, 2015); System.out.println("Week of month " + cal.get(Calendar.WEEK_OF_MONTH)); System.out.println("Day of week in month " + (cal.get(Calendar.DAY_OF_WEEK_IN_MONTH))); System.out.println("Day " + cal.get(Calendar.DAY_OF_MONTH)); System.out.println("Month " + (Calendar.MAY == cal.get(Calendar.MONTH) ? "May" : "April"));
Select the correct answerWhat is the output of the following Java code snippet?int dayOfWeek = 3;switch (dayOfWeek) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; default: System.out.println("Other day");}OptionsWednesdayTuesdayMondayOther day
Write a program to print corresponding day based on given inputInput Format:Accept integer as a inputOutput Format:Print corresponding day(0-6) or "Invalid" day- Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,SaturdayConstraints:1 <= day_num <= 10^15Sample Input 1:6Sample Output 1:SaturdaySample Input 2:0Sample Output 2:Sunday
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.