Back To Java Loops Index
//program to find sum of even and odd numbers between a and b using while statement public class whilesumevenoddatob { public static void main(String[] args) { int a,b,i; int sumeven=0; int sumodd=0; a=5; b=15; i=a; while(i<=b) { if(i%2==0) { sumeven=sumeven+i; } else { sumodd=sumodd+i; } i++; } System.out.println("sum of even numbers between a and b is " + sumeven); System.out.println("sum of odd numbers between a and b is " + sumodd); } }