➽ Program:-
import
java.util.*;
import
java.io.*;
public
class Main
{
public static void main(String args[])
{
int i, number, even = 0, odd = 0;
Scanner s = new Scanner(System.in);
number = s.nextInt();
System.out.print("Enter a Number:
");
for(i = 0; i <= number; i++)
{
if(i % 2 == 0)
{
even = even + i;
}
else
{
odd = odd + i;
}
}
System.out.print("Sum of all Even
Numbers: "+ even);
System.out.print("Sum of all Odd
Numbers: "+ odd);
}
}
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.