Ok, so for learning purposes making some code. Wanted to have a nice line to print where the console would ask the user to present a day of the week.
Now when I try to use system.out.println() the string displays properly and where it is supposed to be. However when I just use print() it doesn't display, or only after I call the catch-block of the errors.
What causes this and how can it be prevented in the future?
public static void dayOfTheWeek(){
System.out.print("Select day:");
try(Scanner sc = new Scanner(System.in)){
int selectedDay = sc.nextInt();
dayOfTheWeek2(selectedDay);
}
catch (Exception e){System.err.print(e);
System.out.println("Faulty Selection...");}
} // end dayOfTheWeek
public static void dayOfTheWeek2(int day){
ArrayList<String> days = new ArrayList<>();
days.add("Monday");days.add("Tuesday");days.add("Wednesday");
days.add("Thursday");days.add("Friday");days.add("Saturday");days.add("Sunday");
int correctedSelection = day-1;
if(correctedSelection > 7){
System.out.println("Faulty selection, please re-try");
dayOfTheWeek();
} else {System.out.println("The day is " + days.get(correctedSelection));}
} // End of dayOfTheWeek2
question from:
https://stackoverflow.com/questions/65545501/system-out-println-in-java-working-but-system-out-print-is-not-displaying-or-w 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…