i am creating a scanner test. I have managed to print even number 1-50. i want to do a scanner code so that when a user inputs i.e 8 it will print all the even number from 8-50.
import java.util.Scanner;
public class ModulusCalculation
{
public static void main(String[] args)
{
int endLimit = 50;
System.out.println("WE ARE GOING TO PRINT EVEN NUMBER FROM 1 AND " + endLimit);
Scanner input = new Scanner(System.in);
for (int startingPoint = 1; startingPoint <= endLimit; startingPoint++)
{
if (startingPoint % 2 == 0)
{
input.nextLine();
System.out.println(+startingPoint);
}
}
}
}
Dont need to read input.nextLine(); within the for loop.
STEP 1: read a starting integer value
STEP 2: for (int startingPoint = startinteger; startingPoint <= endLimit; startingPoint++)
STEP3: print all the even numbers based on the condition within the for loop