Planet Terra still has "offices"—an outdated type of workspace. With current technology, there is no need for them, but earthlings tend to be nostalgic and haven't been in a hurry to eradicate them. Terrestrial office workers develop "TGIF syndrome": they constantly want to know what day of the week it is. Let's write a program for them!
Day of the week
- 4
Locked
Comments (23)
- Popular
- New
- Old
You must be signed in to leave a comment
Lunita
5 February, 03:10
Fairly easy, I did it by using a lot of "if else" and the operators || and ==
0
DavidJugaad
19 July 2021, 16:35
Hey guys,
First, this code solution works.
I´m not asking for help, but I would like to receive feedback.
I´ve seen solutions of other users with swith/case, and nested ifs in the main body of the solution.
Can anybody suggest me a more compact solution than mine plz?
I´ve tried to give a solution following OOP paradigm wich means reuse code creating a method, and using an array to have a more easy to read code...
0
Samuel
26 March 2021, 12:36
Either [switch/case] or [if/else] statements are excellent. Indeed there are some differences between these two, but if you can complete the task with either then thumb up!
+2
Pahunchik
10 March 2021, 14:51
Hi everyone)
Why it's wrong?
BufferedReader str = new BufferedReader(new InputStreamReader(System.in));
String daystr = str.readLine();
int daynum = Integer.parseInt(daystr);
if (daynum = 1) ---> error: int cannot be converted to boolean
0
Roman
12 March 2021, 07:31
because the comparison is "=="
+2
Shellie
28 January 2021, 21:06
This question is outdated. Offices are so 2019 😋
0
M Till
24 July 2020, 22:07
try to switch up your thinking!
;) ;) ;)
+2
Sean Nigito
29 July 2020, 21:23
yeah a switch statement works really well
+3
Laura
13 August 2020, 12:19
What is the switch statement?
0
Sean Nigito
14 August 2020, 23:40
It is sort of like a chain of if else statements but looks for a specific input
Here is a better explanation:
https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.homeandlearn.co.uk%2Fjava%2Fjava_switch_statements.html&psig=AOvVaw2KXyPI_gGvfEmshgWQAQDH&ust=1597534748860000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCPiUpevum-sCFQAAAAAdAAAAABAD
+1
HaeWon Chung
17 January 2020, 01:35
I was able to pass but I had to use
which I haven't learned it yet. Is there anyway to solve it without converting string into int? Or did I miss any lessons? +2
Skynet
31 October 2019, 15:29
Used a more advanced code, which we have not covered so far.
Created a String array, to which I added "No such day of the week" and all of the days of the week in the correct order (i.e. 8 entries in total).
Then used an if statement with a condition: if the entered day of the week is higher than 0 AND less than 8, then output the entry of the array which corresponds to the entered number by index (i.e. if you entered 2, then you will get "Tuesday").
Did not need any conditions in the else statement, just the output of the first index of the array (e.g. yourArray[0]), which means that the true output will be the "No such day of the week" text, which is assigned to the first index of the array.
0
Steve
23 June 2019, 12:50
I used switch,, it works fine
+1
shabarish kumar
19 May 2019, 05:28
Are we not supposed to use Switch here!
+1