Answer to Question #317906 in Java | JSP | JSF for lolo

Question #317906


 

 

4.      Write a program (without using an array) that accepts three numbers from the user and prints "increasing" if the numbers are in increasing order, "decreasing" if the numbers are in decreasing order, and "Neither increasing or decreasing order" otherwise.

 

Example: Input first number: 1524

Input second number: 2345

Input third number: 3321

 

Expected Output :

 

Increasing order

 

5.      Write a java program that inputs an integer and outputs if the number is a Palindrome.

 




1
Expert's answer
2022-03-25T08:40:55-0400




import java.util.*;


class App {


	public static void main(String[] args) {


		Scanner keyboard = new Scanner(System.in);
		System.out.print("Input first number: ");
		int number1 = keyboard.nextInt();
		System.out.print("Input second number: ");
		int number2 = keyboard.nextInt();
		System.out.print("Input third number: ");
		int number3 = keyboard.nextInt();


		if (number2 > number1 && number3 > number2) {
			System.out.println("Increasing order");
		} else if (number2 < number1 && number3 < number2) {
			System.out.println("Decreasing order");
		} else {
			System.out.println("Neither increasing or decreasing order");
		}


		keyboard.close();
	}


}






import java.util.Scanner;


public class App {


	static boolean isNumPalindrome(int number) {
		int temp = number;
		int sum = 0;
		while (number > 0) {
			int r = number % 10;
			sum = (sum * 10) + r;
			number = number / 10;
		}
		return (temp == sum);
	}


	/**
	 * The start point of the program
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		System.out.print("Enter number: ");
		int number = keyBoard.nextInt();
		if (isNumPalindrome(number)) {
			System.out.println("The number is a palindrome\n\n");
		} else {
			System.out.println("The number is NOT a palindrome\n\n");
		}
		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