Your friends asked for your help in solving a coding problem. They were trying to create a utility method for swapping two integer numbers, but something went wrong and the method does not work as expected. Use your debugging skills to fix the problem.
Debugging techniques
Find the error
Report a typo
Sample Input 1:
29
-16Sample Output 1:
-16
29Write a program in Java 17
import java.util.Scanner;
class Util {
public static int[] swapInts(int[] ints) {
return new int[]{ints[1], ints[0]};
}
}
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] ints = new int[2];
ints[0] = Integer.parseInt(scanner.nextLine());
ints[1] = Integer.parseInt(scanner.nextLine());
Util.swapInts(ints);
System.out.println(ints[0]);
System.out.println(ints[1]);
}
}
___
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.