Computer Science, asked by ahcnarayan111, 7 months ago

input a number and count the even numbers from 1 to that number in java programming ​

Answers

Answered by nishuarya2000
1

Answer:

public class DisplayEvenNumbersExample1

{

public static void main(String args[])

{

int number=100;

System.out.print("List of even numbers from 1 to "+number+": ");

for (int i=1; i<=number; i++)

{

//logic to check if the number is even or not

//if i%2 is equal to zero, the number is even

if (i%2==0)

{

System.out.print(i + " ");

}

}

}

}

Explanation:

Inside the method, we have used nested-if statement.

Similar questions