package javaapplication5;
public class JavaApplication5 {
public static void main(String[] args)
{
int esum=0,osum=0,tsum=0;
for (int i = 1; i <= 100; i++)
{
if (i%2==0)
{
esum=esum+i;
}
else if (i%2!=0)
{
osum=osum+i;
}
tsum=tsum+i;
}
System.out.println("Sum of even no is "+esum);
System.out.println("Sum of odd no is "+osum);
System.out.println("Total from addition "+(esum+osum));
System.out.println("Total from loop "+tsum);
}
}
No comments:
Post a Comment