write a java program to print first 10 odd numbers from 51
Answers
Answer:-
- There are two ways to do this
Method 1:- Using only 1 variable
//Program to display first 10 odd numbers from 51
package Programmer;
public class OddPrint{
public static void main (String ar []){
System.out.println("The first 10 Odd numbers from 51 are as follows:-");
for(int I=51;I<71;I+=2)
System.out.println(I);
}
}
Method 2: Using 2 Variables
//Program to display first 10 odd numbers from 51
package Programmer;
public class OddPrint{
public static void main (String ar []){
System.out.println("The first 10 Odd numbers from 51 are as follows:-");
int d=51;
for(int I=1;I<=10;I++){
System.out.println(d);
d+=2;}
}
}
___
•Output Attached
Answer:
numbers from 1 to n or 1 to 100
numbers from 1 to n or 1 to 100BY CHAITANYA SINGH | FILED UNDER: JAVA EXAMPLES
numbers from 1 to n or 1 to 100BY CHAITANYA SINGH | FILED UNDER: JAVA EXAMPLESIn this example, we will write a Java program to display odd numbers from 1 to n which means if the value of n is 100 then the program will display the odd numbers between 1 and 100.
numbers from 1 to n or 1 to 100BY CHAITANYA SINGH | FILED UNDER: JAVA EXAMPLESIn this example, we will write a Java program to display odd numbers from 1 to n which means if the value of n is 100 then the program will display the odd numbers between 1 and 100.Program to print odd numbers from 1 to n where n is 100
numbers from 1 to n or 1 to 100BY CHAITANYA SINGH | FILED UNDER: JAVA EXAMPLESIn this example, we will write a Java program to display odd numbers from 1 to n which means if the value of n is 100 then the program will display the odd numbers between 1 and 100.Program to print odd numbers from 1 to n where n is 100In the following example we have provided the value of n as 100 so the program will print the odd numbers from 1 to 100.
numbers from 1 to n or 1 to 100BY CHAITANYA SINGH | FILED UNDER: JAVA EXAMPLESIn this example, we will write a Java program to display odd numbers from 1 to n which means if the value of n is 100 then the program will display the odd numbers between 1 and 100.Program to print odd numbers from 1 to n where n is 100In the following example we have provided the value of n as 100 so the program will print the odd numbers from 1 to 100.The logic we are using in this program is that we are looping through integer values from 1 to n using for loop and we are checking each value whether the value%2 !=0 which means it is an odd number and we are displaying it. To understand this program, you should have the basic knowledge of for loop and if statement.