1. WAP in java to display all odd numbers and their sum in the range 50 to 100 (java)
Answers
Answered by
7
The given problem is solved using language - Java.
public class Java{
public static void main(String s[]){
int i,sum=0;
System.out.println("Odd numbers in the range 50 to 100 are as follows...");
for(i=51;i<=100;sum+=i,i+=2)
System.out.print(i+" ");
System.out.println("\nSum of the numbers: "+sum);
}
}
- Initialize sum = 0.
- Repeat i = 51 to 100.
- Add 'i' to sum.
- Display the value of 'i'.
- Increment the value of 'i' by 2.
- If i > 100, terminate the loop.
- Display the 'sum'.
See attachment for output.
Attachments:
Similar questions