Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SumOfOddNumbers {
- public static void main(String[] args) {
- int input = new Scanner(System.in).nextInt();
- int number = 0;
- int counter =0;
- int sum = 0;
- while (counter < input){
- number++;
- if (number %2 ==1) {
- sum += number;
- System.out.println(number);
- counter++;
- }
- }
- System.out.println("Sum: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement