Answer to Question #287165 in Programming & Computer Science for Bjoy

Question #287165

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






1
Expert's answer
2022-01-13T07:46:54-0500


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.print(i + " ");
		}
		System.out.println("\nNumber in DESCENDING orders");
		for (int i = number; i >= 1; i--) {
			System.out.print(i + " ");
		}
		System.out.println("\nEVEN Number");
		for (int i = 1; i <= number; i++) {
			if (i % 2 == 0) {
				System.out.print(i + " ");
			}
		}
		System.out.println("\nODD Number");
		for (int i = 1; i <= number; i++) {
			if (i % 2 == 1) {
				System.out.print(i + " ");
			}
		}


		keyBoard.close();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS