input a number and count the even numbers from 1 to that number in java programming
Answers
Answered by
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
Computer Science,
3 months ago
Computer Science,
3 months ago
History,
7 months ago
Social Sciences,
1 year ago
India Languages,
1 year ago
History,
1 year ago