Question

Randomly generate an integer number in range [10, 99]. Write a program to check if the...

Randomly generate an integer number in range [10, 99]. Write a program to check if the digit at 10’s position is less than the digit at 0’s position. If yes, swap these 2 digits. Display original number and new number. For example, if the number generated is 53, after process, the new number will be 35. If original number is 12, no process needed. If the number is 50, the new number will be 5.

in Java please

Homework Answers

Answer #1
import java.util.Random;

public class DigitsSwap {

    public static void main(String[] args) {
        Random random = new Random();
        int num = random.nextInt(90) + 10;
        System.out.println("number is " + num);
        if (num / 10 > num % 10) {
            int newNumber = (num % 10) * 10 + (num / 10);
            System.out.println("new number is " + newNumber);
        } else {
            System.out.println("No process required.");
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Java : Randomly generate an integer number in range [10, 99]. Write a program to...
In Java : Randomly generate an integer number in range [10, 99]. Write a program to check if the digit at 10’s position is less than the digit at 0’s position. If yes, swap these 2 digits. Display original number and new number. For example, if the number generated is 53, after process, the new number will be 35. If original number is 12, no process needed. If the number is 50, the new number will be 5.
Randomly generate an integer number in range [1, 999], (a) Check if this number is even...
Randomly generate an integer number in range [1, 999], (a) Check if this number is even or odd, display message “[number] is an even number” or “[number] is an odd number”. For example, if the number is 10, display message “10 is an even number”. (b) Check if this number is divisible by 7 and 11. Display message showing result (c) Check if this number is divisible by 9 or 13. Display message showing result (d) Check if this number...
Write program to generate random numbers in different range and display: (c) A number in range...
Write program to generate random numbers in different range and display: (c) A number in range [0, 10) (d) A number in range [0, 1000] (e) A number in range [-99, 99] (f) A double number in range [1000.0, 9999.0) In Java Please
Write a C++ program to read a positive integer greater than 0, the program should compute...
Write a C++ program to read a positive integer greater than 0, the program should compute and display the following: - Sum of odd digits in the number - Count of even digits in the number - The smallest digit.                    For example, if the input is 24536, then Sum of odd digits in the number = 8 Count of even digits in the number = 3 Smallest digit = 2
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
Using the Java language program Demonstrate multiway if statement 1.1 Generate an integer random number from...
Using the Java language program Demonstrate multiway if statement 1.1 Generate an integer random number from -5 to 5.(Hint: Use Math.random()) 1.2 Write a multiway if statement that will display whether the number is positive, negative or zero. 1.3 Be sure to test your code with all three cases
How to write a C++ program. Additive persistence is a property of the sum of the...
How to write a C++ program. Additive persistence is a property of the sum of the digits of an integer. The sum of the digits is found, and then the summation of digits is performed creating a new sum. This process repeats until a single integer digit is reached. Consider the following example: 1. The beginning integer is 1234 2. Sum its digits is 1+2+3+4 = 10 3. The integer is now 10 4. The sum of its digits is...
Write a complete program that will generate equally likely random shoe sizes in the inclusive range...
Write a complete program that will generate equally likely random shoe sizes in the inclusive range [5, 13.5], with whole or half sizes allowed. The number of values to generate will be input by the program user. It will also count and display the total number of times small (5, 5.5, 6, 6.5) and large (12, 12.5, 13, 13.5) sizes are generated. We have provided skeleton code for you to use. You must implement the helper method as given in...
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...