Playing Compiler
Determine the errors in each of the following segments. Fix the errors and then
determine the output. Unusual formatting is not an error.
a.
public class WhatTheHey{ public static int method1(int x,y) { return x + y; } public int method2(double x, double y) { return int(x − y); } public static void main(String[] args) { System.out.println(“The output is: ”, method1(method2(7.1, 6.2), method1(2, 3)) “years of bad luck” ); }}b. public class TheBookOnLove { public static void method1() { System.out.println(“I wonder who wrote the book on love”); } public static void method1(int x) { for (i = 0; i
c.
public class ThisComputesSomeWeirdStuff{ public static int method1(int a, int b) { if (a%2 == 0) return (a) else return (b) } public static int method2(int a, int b) { while (a ! = 1) {b++; a = a / 2;} return (b); } public static void main{String[] args} { System.out.println(method2(method1(3, 10), method1(16, 57))); System.out.println(method2(method1(190, 10), method1(16, 57))); System.out.println(method2(method2(3, 10), method1(16, 57))); System.out.println(method1(method2(3, 10), method2(16, 57))); }}
d.
public class ThisOneIsPrettyCool{ public static int method1(int w) { int count _ 0; while (w != 1) if (w % 2 == 0) { w == w / 2; count++; } else w = 3 * w + 1; return count; } public static void main(String[] args) { System.out.println(method1(10)); System.out.println(method1(7)); }}
e.
public class OkIveHadEnough{ public static double method1(int a) { return a / 2;} public static double method1() {return 1.0;} public static int method2(double x) {return 3 * (int)x;} public static int method2() {return 0;} public static void main(String[] args) { System.out.println(method2(method1())); System.out.println(method1(method2())); for (int j = 0; j = 10; j++) { System.out.println(method2(method1(j)); System.out.println(method1(method2(j))); } }}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.