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
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."); } } }
Get Answers For Free
Most questions answered within 1 hours.