We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c0aa1c9 commit 1a05544Copy full SHA for 1a05544
Test10_Sum_odd_or_Even.java
@@ -0,0 +1,48 @@
1
+package com.test.Basic_Java_Programs;
2
+
3
+import java.util.Scanner;
4
5
+public class Test10_Sum_odd_or_Even
6
+{
7
+ public static void main(String[] args)
8
+ {
9
+ int n, sum=0;
10
11
+ System.out.print("Enter a Number : ");
12
13
+ Scanner sc = new Scanner(System.in);
14
15
+ n = sc.nextInt();
16
17
+ if (n%2==0)
18
19
+ for (int i = 0; i <= n; i=i+2)
20
21
+ sum = sum + i;
22
+ }
23
+ System.out.println("Sum of Even Number is : " + sum);
24
25
26
+ else
27
28
+ for (int i = 1; i <= n; i=i+2)
29
30
31
32
+ System.out.println("Sum of odd Number is : " + sum);
33
34
35
36
37
+}
38
39
40
+/* Output:
41
42
43
+Enter a Number : 20
44
+Sum of Even Number is : 110
45
46
47
48
+*/
0 commit comments