Question

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.

Answer #1

**I WROTE THE CODE ALONG WITH THE COMMENTS**

**CODE:**

public class Main

{

public static void main(String[] args)

{

//variables declaration.

int low=10,high=100,new_num=0;

int random_num= (int) (Math.random() * (high - low)) +
low; //random number generator.

//separate two digits.

int zeros_pos=random_num/10;

int tenth_pos=random_num%10;

if(tenth_pos<=zeros_pos) //condition compare two
digits.

{

//calculate new number.

new_num=(new_num*10)+tenth_pos;

new_num=(new_num*10)+zeros_pos;

//print new number.

System.out.println("original number:
"+random_num);

System.out.println("new number: "+new_num);

}

else

System.out.println("original number:
"+random_num);

}

}

**OUTPUT:**

**SCREENSHOT OF THE CODE:**

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 [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 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 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...

Meant to be written in Java JDK 14.0
Generate four (4) integer numbers in range [0, 100]. Use Math
methods to: (a) find the maximum and minimum numbers and display
(b) calculate the absolute difference between the maximum number
and minimum numbers, display

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 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 Java program named BinaryConversion that will convert
base 2 numbers to base 10 numbers. The data for this program will
be entered from the keyboard using JOptionPane one 16-bit binary
number at a time. Note that each base 2 number is actually read in
as a String. The program should continue until a 16-bit base 2
number consisting of all 0’s is entered. Once the 16-bit number has
been entered your program should make sure that the input...

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...

Write a complete recursive java program to compute the heights
of the tick marks on a ruler. Assume that the length of the ruler
is a power of 2 (say L=2^n, where n >=1) , and the marks are to
be placed at every point between 0 and 2^n, not including the
endpoints.
The endpoints 0 and 2^n will have height 0. Here are the rules
for computing the heights of the ticks for a ruler of length
L=2^n:
1....

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 12 minutes ago

asked 24 minutes ago

asked 31 minutes ago

asked 33 minutes ago

asked 39 minutes ago

asked 40 minutes ago

asked 44 minutes ago

asked 52 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago