What is the program about?
This program has 2 tasks.
One is to print all the even numbers from 0 to 100
Second is to enter a number between 1 to 10 and have the program print every nth number between 0 and 100. For example, if you enter 5 then 0, 5, 10, 15, 20 .. 95, 100 is printed.
What is the problem?
I already completed task one. And second task I think I am almost done is to print the nth number but I need the formula that finds the nth number.
So how can that be done.
import java.util.Scanner; public class EvenNums { public static void main( String args[]) { int evenNum=2; int number; int i; Scanner s = new Scanner(System.in); for(evenNum=2;evenNum<=100;evenNum+=2) System.out.print(evenNum + " "); System.out.print("\nEnter a number between 1 to 10 to get nth result:"); number = s.nextInt(); while (number >= 1 && number <= 10) for (i=0; i<=100; i++){ { System.out.println(number); } } } }