0

How to print something before it scans an input in the same program?

import java.util.Scanner; public class Program { public static void main(String[] args) { int day; System.out.println("enter week number between 1-7"); Scanner hell=new Scanner(System.in); day=hell.nextInt(); System.out.println(day); switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; default: System.out.println("off day"); } } }

17th Oct 2018, 4:03 PM
Fakeid
6 ответов
+ 1
Tip - Mention which input user has to give, in a comment at the beginning of the code. Like this - /* * Enter a number between 1 to 7 * Any other input if wanted */ import java.util.Scanner; public class Program { ...
18th Oct 2018, 4:31 AM
Rugved Modak
Rugved Modak - avatar
+ 1
Thanks a lot for both ideas.😊 I will improve my code in SL adding this comment.
18th Oct 2018, 4:38 AM
Fakeid
0
Whaa? Which line? Where? When?
17th Oct 2018, 5:52 PM
Rugved Modak
Rugved Modak - avatar
0
"enter week number between 1-7"= i want this line to be printed before it asks the user for input but it's not happening.
17th Oct 2018, 6:08 PM
Fakeid
0
After giving the input, the code is telling "enter week no. between 1-7" How would user get to know that he has to put numbers only between 1 to 7 if it will be printed after user has given the input.
17th Oct 2018, 6:19 PM
Fakeid
0
If you are talking about SL, then it cannot happen. SL lacks in interactive input system. Try same code on other IDE and your code will work.
18th Oct 2018, 4:26 AM
Rugved Modak
Rugved Modak - avatar