Skip to content

Commit 842e464

Browse files
authored
🍵
1 parent 4630025 commit 842e464

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

challenge17.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Scanner;
2+
3+
// Create a program to sum all odd numbers from 1 to a specified number N.🚀
4+
public class challenge17 {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
System.out.println("Welcome to ODD SUM");
8+
System.out.print("Please enter your number: ");
9+
int num = sc.nextInt();
10+
int sum = oddsum(num);
11+
System.out.println("ODD SUM till " + num + " is: " + sum);
12+
}
13+
14+
public static int oddsum(int num){
15+
int sum = 0;
16+
int i = 1;
17+
while(i <= num){
18+
sum += i;
19+
i += 2;
20+
}
21+
return sum;
22+
}
23+
}

0 commit comments

Comments
 (0)