So first off, I'm completely brand new to Java and I know this is probably really easy for most of you. But right now I'm stuck with an exercise. I have googled almost frantically, but I can't find any helpful tips to this particular problem. That or I don't really know what to search for.
I have a piece of code that looks like this:
import java.util.Scanner;
public class Week {
public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("Type a number: ");
int day = input.nextInt();
if (day == 1) {
System.out.println("Monday ");
}
if (day == 2) {
System.out.println("Tuesday ");
}
if (day == 3) {
System.out.println("Wednesday ");
}
if (day == 4) {
System.out.println("Thursday ");
}
if (day == 5) {
System.out.println("Friday ");
}
if (day == 6) {
System.out.println("Saturday ");
}
if (day == 7) {
System.out.println("Sunday");
}
} }
As all you can probably see, this program prompts the user to type a number, and if that number is somewhere between 1-7 the program will answer with the corresponding day of the week. What I would like to do now however, is to modify the code to start a counter or loop or something. I want to make it count +1 from my input number to a specified break. Let's say I type 2, and the program would print: Tuesday, Wednesday, Thursday, Friday and then make it stop.
I have only really dipped my toe in for, while, if statements etc but I know that somewhere there is the key. While playing around I only succeeded in making the program print 2 five times, or letting me type numbers for infinity.
Any help would be greatly appreciated!