+ 1
can you help to solve this in java
Declare and initialize the days of the week. Print and output them using the for loop. Create a condition that if the day is Friday, print âTGIFâ instead of the word âFridayâ. Sample output: Monday Tuesday Wednesday Thursday TGIF Saturday Sunday
6 Answers
+ 7
Miss Cuteđ„ș
Please specify which language you are using, and also post your attempt.
That way, we can assist you by identifying where you are struggling.
I would suggest you declare your items inside an array / list
Iterate through the list testing each item using an IF statement.
if Friday, print TGIF else print the item, (day of week)
+ 2
oww sorry this is java
+ 2
In java you can use the for each loop - it will be almost like in python ))))
Java:
for (String day : daysOfTheWeek) {
if (day == "Fri")
System.out.println("TGIF");
else
System.out.println(day + "day")
}
Python:
For day in daysOfTheWeek:
If day == "Fri":
print("TGIF")
else:
print(day + "day")
+ 1
Here is a Python solution:
https://code.sololearn.com/cnY8SL3d6T12/?ref=app
+ 1
Here is a Java solution:
https://code.sololearn.com/cS1Naj4AioXW/?ref=app
+ 1
days of the week with the encapsulation principle :)
https://code.sololearn.com/cS7BWxnCmkBH/?ref=app