+ 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

30th Dec 2018, 1:38 PM
Ahmad Ali
Ahmad Ali - avatar
7 odpowiedzi
+ 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 }
30th Dec 2018, 2:01 PM
Sekiro
Sekiro - avatar
+ 4
If you want just print days/months maybe you should use arrays with these values
30th Dec 2018, 2:04 PM
Michal
Michal - avatar
+ 2
Sekiro many thanks man 👍
30th Dec 2018, 3:18 PM
Ahmad Ali
Ahmad Ali - avatar
+ 2
Sekiro many thanks man 👍
30th Dec 2018, 3:19 PM
Ahmad Ali
Ahmad Ali - avatar
+ 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
30th Dec 2018, 2:05 PM
Sekiro
Sekiro - avatar
+ 1
Use switch statment
19th Feb 2019, 2:21 AM
Mohamed
20th Feb 2019, 12:58 AM
Ahmad Ali
Ahmad Ali - avatar