This program asks the user to enter the limit and then calculates the sum of all even numbers from 1 up to the entered limit. Here's how the program works:
import java.util.Scanner; class Sum_Even_Number { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter The Number of Limit : "); int l =input.nextInt(); int sum = 0; for(int s=1;s<=l;s++) { if(s%2==0) sum = sum + s; } System.out.println("Sum of Even Numbers :"+sum); } }
Enter The Number of Limit : 30 Sum of Even Numbers :240
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions