7. Write a Java program to find sum of all even numbers between 1 to n. Static class loop7 { public static void main(String args[]) { int i=1,n=20,sum=0; while(i<=n) { if(i%2==0) sum = sum + i; i++; } System.out.println(sum); } } Output :- Dynamic :- import java.util.*; class loop7 { public static void main(String args[]) { Scanner in = new Scanner(System.in); int i,j,sum=0; System.out.println("Enter the First number:- "); i=in.nextInt(); System.out.println("Enter the Last number:- "); j=in.nextInt(); while(i<=j) { if(i%2==0) sum =sum +i; i++; } System.out.println(sum); } } Output :-
All computer course for class 9th to 12th with proper practical and theory .........