1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* List Odd Numbers Java Example This List Odd Numbers Java Example shows how to find and list odd numbers between 1 and any given number. */ public class ListOddNumbers { public static void main(String[] args) { //define the limit int limit = 50; System.out.println("Printing Odd numbers between 1 and " + limit); for(int i=1; i <= limit; i++){ //if the number is not divisible by 2 then it is odd if( i % 2 != 0){ System.out.print(i + " "); } } } } /* Output of List Odd Numbers Java Example would be Printing Odd numbers between 1 and 50 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 */ |
The decleration of limit is wrong as an integer. Why not int j=50; and the condition be for (int i=1; i<j; i++)=”” {=””>
how to find the largest odd or even number from this coding?please help me.(‘:
thank u work correct
good work
its not working
sum of first 50 odd numbers in JAVA
public class Fifty {
public static void main(String[] args) {
int sum=0;
System.out.println(“the sum of first 50 number is :”);
for(int i=1;i<=50;i++)
{
sum=i+sum;
}
System.out.print(sum );
}
}
write a program to input a number & print its odd factor and sum of its odd factors
write a program that will out all the odd numbers found in array of 20 integers display also the sum of the values found.. guys can you help me please.
Any one have solution of these program.
1 2
4 3
5 6
8 7
9 10
why mine still having error please help i need odd numbers for my school homework.