3
Write a program to input ten different numbers. Display the sum of
only odd numbers by using for loop.
guys do it by loop condition
Share
3
Write a program to input ten different numbers. Display the sum of
only odd numbers by using for loop.
guys do it by loop condition
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Required Answer:-
Question:
Solution:
Here is the program.
import java.util.*;
public class OddSum {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter 10 numbers. ");
int s=0;
for(int i=0;i<10;i++) {
System.out.print("Enter: ");
int x=sc.nextInt();
if(x%2==1 || x%2==-1)
s+=x;
}
System.out.println("Sum is: "+s);
sc.close();
}
}
Explanation:
Output is attached.