Write a program using for loop statement that will display a series of number in ascending and descending order and it will also display the odd and even numbers.
Note: Use scanner and for loop statement
Sample output:
Enter a number: 15
Number in ASCENDING orders
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Number in DESCENDING orders
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
EVEN Number
2
4
6
8
10
12
14
ODD Number
1
3
5
7
9
11
13
15
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
int number;
System.out.print("Enter a number: ");
number = keyBoard.nextInt();
System.out.println("\nNumber in ASCENDING orders");
for (int i = 1; i <= number; i++) {
System.out.println(i);
}
System.out.println("\nNumber in DESCENDING orders");
for (int i = number; i >= 1; i--) {
System.out.println(i);
}
System.out.println("\nEVEN Number");
for (int i = 1; i <= number; i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
System.out.println("\nODD Number");
for (int i = 1; i <= number; i++) {
if (i % 2 == 1) {
System.out.println(i);
}
}
keyBoard.close();
}
}
Comments
Leave a comment