+ 4
i want to get the day and the month written when i enter them in numbers.
for example, if i enter: 1 1 i wanna get Monday January. shall I need to separate them into two classes? one is the main, how i can enter the new class. https://code.sololearn.com/cXf431a2BHF8/?ref=app
7 Answers
+ 2
Here it works like this, i added some comment on where it was wrong:
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
int day;
Scanner dayScan =new Scanner(System.in);
day = dayScan.nextInt();
switch(day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
}
// <- here you had one useless }
int mon;
//here you dont need to create a new scanner object use the same
mon = dayScan.nextInt();
switch(mon) {
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
}
}
} // <- here you missed the }
+ 4
If you want just print days/months maybe you should use arrays with these values
+ 2
Sekiro many thanks man đ
+ 2
Sekiro many thanks man đ
+ 1
In case you didnt know on sololearn playground you have to input the values like this:
1
1
and you will get:
monday
jenuary
+ 1
Use switch statment