I need help fixing this code. Please provide the correct code by changing the sy
ID: 3783475 • Letter: I
Question
I need help fixing this code. Please provide the correct code by changing the syntax errors. Here is the exercise:
Fix the code in Oops1.java. There are at least 7 different syntax mistakes. You do not need to rewrite the logic, the errors are only syntax errors. Here is the code:
//This program will display the smaller of the two
//numbers a and b. Assume that a and b will never be
//equal.
import java.util.Scanner;
public class Oops1 {
public static void main(String[] args) {
int a = 7; b = 42; //declaration of local variables.
minimum(int a,int b); //call method to find the min. of a and b.
if (smaller = a) // this branch is taken if a is < b.
System.out.println("a is the smallest!");
else System.out.println("b is the smallest!");
}
public static void minimum(int a, int b){
if (a < b){
int smaller = a;
}else (a => b) {
int smaller = b;
}
//return the variable smaller, which should contain the smaller of a & b.
return int smaller;
}
}
Explanation / Answer
Following is the code without syntax error:
import java.util.Scanner;
public class Oops1 {
public static void main(String[] args) {
int a = 7;
int b = 42; //declaration of local variables.
int smaller= minimum(a,b); //call method to find the min. of a and b.
if (smaller == a) // this branch is taken if a is < b.
System.out.println("a is the smallest!");
else System.out.println("b is the smallest!");
}
public static int minimum(int a, int b){
int smaller;
if (a < b){
smaller = a;
}else
{
smaller = b;
}
//return the variable smaller, which should contain the smaller of a & b.
return smaller;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.