1) The UsingMethod class consists of a main method and a method called xMethod. What will the code print? public class UsingMethod {public static void main(String[] args) {double z = xMethod(3.5, 5.5);System.out.println(z);}public static double xMethod(double x, double y) {return x + y;}} 2) Identify the errors in the following programs a) 3 errorspublic class Test {public static void main(String[] args) {System.out.println(method2(3.4));} public static int method1(int n) {if (n > 0) return 1;else if (n == 0) return 0;else if (n < 0) return -1;}} b) 2 errorspublic class Test {public static void main(String[] args) {nPrintln(5, "Welcome to Java!");}public static void nPrintln(String message, int n) {for (int i = 0; i < n; i++) {System.out.println(message);}return n;}}
1) The UsingMethod class consists of a main method and a method called xMethod. What will the code print?
public class UsingMethod {
public static void main(String[] args) {
double z = xMethod(3.5, 5.5);
System.out.println(z);
}
public static double xMethod(double x, double y) {
return x + y;
}
}
2) Identify the errors in the following programs
a) 3 errors
public class Test {
public static void main(String[] args) {
System.out.println(method2(3.4));
}
public static int method1(int n) {
if (n > 0) return 1;
else if (n == 0) return 0;
else if (n < 0) return -1;
}
}
b) 2 errors
public class Test {
public static void main(String[] args) {
nPrintln(5, "Welcome to Java!");
}
public static void nPrintln(String message, int n) {
for (int i = 0; i < n; i++) {
System.out.println(message);
}
return n;
}
}

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









