Print the sum square for num1 and num2 using a get() method to get their values before assigning null to both of them.
Types of references
Get the sum square of variables
Report a typo
Sample Input 1:
3
4Sample Output 1:
49Write a program in Java 17
import java.util.Scanner;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Integer num1 = scanner.nextInt();
Integer num2 = scanner.nextInt();
// Initialize an instance of SoftReference by passing num1 to the constructor
SoftReference<Integer> softReference = ...
// Initialize an instance of WeakReference by passing num2 to the constructor
WeakReference<Integer> weakReference = ...
num1 = null;
num2 = null;
System.out.println((int) Math.pow(/* print the sum here */, 2));
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.