👤

A. Debugging
Directions: Identify the errors in the following codes.
1.
a. public class LoopSample {
b. public static void main (Stringargs) {
c. Int sum=0
d. int x;
e. for(x=1 x < 10 x++)
f. sum+=x;
g. System.out.print("The sum of numbers from 1 to 10 is: " + );
h. }
i. }


2.
a. public class PrintAsterisk {
b. public static void main(String[] args) {
c. Int x
d. int ;
e. for (x = 1; <= 5; x++) {
f. for (y = x; y <= 5; y++)


Sagot :

1. b. Stringargs shoud be String[] args

c. Int sum=0 should be int sum = 0;

e. Missing semicolons and opening curly brace in the for loop. Should be for(x=1; x<10; x++){

g. Invalid binary operation +: Missing Right Hand Operand: should be: System.out.print("The sum of numbers from 1 to 10 is: " + sum );

Note: In the for loop line e: Replace operator < with <=

Note: Swap lines g and h. The full corrected code is below:

public class LoopSample {

public static void main (Stringargs) {

int sum=0;

int x;

for(x=1; x <= 10; x++){

sum+=x;

}

System.out.print("The sum of numbers from 1 to 10 is: " + sum);

}

2. Lines c-f. Invalid syntax:

c. Missing semicolon

d. Missing variable name

e. Missing left hand operand in <= operator

f. Missing {

Note: The code is incomplete and cannot determine what it does. Also missing of matching } in lines e and f, and another } and } for the main function and the class.