write a program to print the first 10 positive odd integers with help of for loop.
Answers
Answered by
30
Required Answer :
Question:
- Write a program to print the first 10 positive odd integers with help of for loop.
Program:
This the required Java program for the question.
class odd
{
public static void main(String args [])
{
int n=20;
System.out.println("Odd numbers:");
{
for (int i = 1; i<= n; i++)
{
if ( i%2!=0)
System.out.println (i);
}
}
}
}
Output:
The output of the given program will be as follows:
Odd numbers:
1
3
5
7
9
11
13
15
17
19
Answered by
5
Answer:
//Java program to print first 10 odd numbers
package Programmer;
public class OddPrint {
public static void main (String ar []){
for(int I=1;I<=20;I+=2){
System.out.println(I);
}
}
}
__
Variable Description:-
- I:- Loop variable
__
Explaination:-
- Intitial value of I is 1
- Each iteration, I is printed and is updated with +2
- loop terminates until I is greater than 20
- finally, program terminates.
- Yay! You made the program to print first 10 odd positive numbers
__
•Output Attached.
Attachments:
Similar questions