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"); } } }
6 Answers
+ 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 {
...
+ 1
Thanks a lot for both ideas.đ I will improve my code in SL adding this comment.
0
Whaa? Which line? Where? When?
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.
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.
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.