Question
My Java code is getting errors in trying to get the following: Write a variation of the largestAbsVal method from the last exercise that takes
My Java code is getting errors in trying to get the following: Write a variation of the largestAbsVal method from the last exercise that takes three integers as parameters and returns the largest of their three absolute values. For example, a call of largest AbsVal(7, -2, -11) would return 11, and a call of (-4, 5, 2) would return 5.
One error is that it says that the int largestAbsVal is not applicable for the arguments (int, int, int).
A second error is that if I put a semicolon after int z, then the int x, y, and z are not initialized. But there is an error if I don't put a semicolon.
Could you please review my code below and critique what I am doing wrong? Thank you.
public class Chapter3 {
public static void main (String [] args) {
printPowersOf2();
int AbsVal=largestAbsVal (7, -2, -11);
int largeAbs=largestAbsVal (-4,5,2);
System.out.println();
System.out.println();
}
public static void printPowersOf2() {
for (int i = 0; i<= 20; i++) {
System.out.print((int) Math.pow(2,i) + " ");
}
System.out.println();
}
public static int largestAbsVal() {int x; int y; int z {
x=Math.abs (x);
y=Math.abs (y);
z=Math.abs (z);
int large = Math.max(x, y);
large=Math.max(large, z);
return large;
}
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started