

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This assignment will focus on the use of random numbers, if statements and the swapping of values in two different variables.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


import java.util.Scanner; public class ValueSwap { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt user to enter an integer value and store it in a variable System.out.println("Enter an integer value:"); int firstValue = scanner.nextInt(); // Generate a random integer between 0 and 99 and store it in a variable int secondValue = (int) (Math.random() * 100 ); // Check if the first value is greater than the second value if (firstValue > secondValue) { // If true, swap the values using a temporary variable int temp = firstValue; firstValue = secondValue; secondValue = temp; } // Output the result of the comparison using the two variables System.out.println(firstValue + " is less than or equal to " + secondValue); } }