Write a program to accept the starting and ending range. Display the sum of even and odd numbers .
import java.util.Scanner;
public class Range
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the starting and ending range:");
int m = sc.nextInt();
int n = sc.nextInt();
if(m<n){
int so=0,se=0;
for(int i=m;i<=n;i++)
{
if(i%2==0)
{
se=se+i;
System.out.println("The even number is:"+i);
}
else{
so=so+i;
System.out.println("The odd number is:"+i);
}
}
System.out.println("The sum of even numbers is:"+se);
System.out.println("The sum of odd numbers is:"+so);
}
else{
System.out.println("Starting range is greater than the ending range");
}
}
}
public class Range
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the starting and ending range:");
int m = sc.nextInt();
int n = sc.nextInt();
if(m<n){
int so=0,se=0;
for(int i=m;i<=n;i++)
{
if(i%2==0)
{
se=se+i;
System.out.println("The even number is:"+i);
}
else{
so=so+i;
System.out.println("The odd number is:"+i);
}
}
System.out.println("The sum of even numbers is:"+se);
System.out.println("The sum of odd numbers is:"+so);
}
else{
System.out.println("Starting range is greater than the ending range");
}
}
}