Try Magic Notes and save time.Try it free
Try Magic Notes and save timeCrush your year with the magic of personalized studying.Try it free

Related questions with answers

Question

Identify and correct the errors in the following program: 1 public class Test { 2 public static method1(int n, m) { 3 n += m; 4 method2(3.4); 5 } 6 7 public static int method2(int n) { 8 if (n > 0) return 1; 9 else if (n == 0) return 0; 10 else if (n < 0) return −1; 11 } 12 }

Solution

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 3

In method1 parameters are not declared correctly. m must be given a type. method1 also has to have defined type. In this case it doesn't return a value so it is void method.

public static void method1(int n, int m)

method2 does not take floating point number as argument, so 3.4 is not a correct input. We can change that to n for example:

method2(n);

Create an account to view solutions

Create an account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263David A. Patterson, John L. Hennessy
226 solutions
Intro to Java Programming, Comprehensive Version 10th Edition by Y. Daniel Liang

Intro to Java Programming, Comprehensive Version

10th EditionISBN: 9780133761313Y. Daniel Liang
1,628 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
895 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
849 solutions

More related questions

1/4

1/7