Find and Fix the 5 errors in the following code. The program output should be a triangle.
For example if the user enters 5, then this will be the output.
x x x x x x x x x x
However there are 3 syntax mistakes and 2 logical mistakes.
Please find and correct them.
The syntax mistakes are underlined please correct them. Find the 2 logical mistakes and correct them too.
import java.util.Scanner;
public class Triangle {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a number (5-20");
int count_row = input.nextDouble();
int i=0, int j=0;
int count_col = 0;
if (5 <= count_col <= 20){
while (i < count_row){
j = 1;
while (j < count_col ){
System.out.print("x ");
}
count_col -= 1;
i++;
System.out.println();
}
}
else
System.out.print("Incorrect, Bye!");
}
}
Line 9 (Syntax Error):
input.nextInt()
Line 10 (Syntax Error):
int i=0, j=0;
Line 13 (Syntax Error):
count_col >= 5 && count_col <= 20
Logical Error:
count_col = count_row;
Line 11…
Logical Error:
Missing j++;
Line 18
need an explanation for this answer? contact us directly to get an explanation for this answer