public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String num = buffer.readLine();
int number = Integer.parseInt(num);
if(number == 1){
System.out.println("Monday");
}if(number == 2){
System.out.println("Tuesday");
}if(number == 3){
System.out.println("Wednesday");
}if(number == 4){
System.out.println("Thursday");
}if(number == 5){
System.out.println("Friday");
}if(number == 6){
System.out.println("Saturday");
}if(number == 7){
System.out.println("Sunday");
}else if(number < 1 | number > 7){
System.out.println("No such day of the week");
}
}
//write your code here
Can't figure out the error
Resolved
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Mohammed Amine EL AMRANI
15 December 2018, 19:52
Hello,
refer to this and you ganna solve the issue :
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
Kind regards;
0
Guadalupe Gagnon
14 December 2018, 16:20
It would be better if you wrote this code as:
Your code actually checks every single condition, even if it finds an 'if' that satisfies the condition. Example: if you enter 1 it checks for 1, 2, 3, 4, 5, 6, 7, and if its not 7 (which 1 certainly is not) it then checks if the entered number falls outside the range of 1-7. This is unnecessary processing that, though it has next to no effect on your small program, could slow down much larger programs that could (hypothetically)call this code thousands of times.
0
Guadalupe Gagnon
14 December 2018, 16:36
so that it looks like this:
You may notice that i don't use the curly brackets { like these } that enclose the code after each if statement. You do not need these as long as the code to execute is 1 and only 1 line, as is your code. If you wanted to do more than 1 line then you would need the brackets, like this:
+1
Marilyn Free
14 December 2018, 17:59
Thank you so much that worked!
+1
Guadalupe Gagnon
14 December 2018, 18:14
No problem! Ask anytime you are stuck, the community here is very helpful.
0