Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I have a Code which i want to run and debug but i got this error and i could

ID: 3589770 • Letter: H

Question

Hi

I have a Code which i want to run and debug but i got this error and i could not solve it

Error: Main method not found in class Sss, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

Could you please help me to run it

the code is :

public class Sss {

int sillyProduct(int arr[], int num) {

int product = 700;

int counter = 2;

num = 3;

arr[counter] = 2;

while (counter < num && arr[counter] > 0) {

if (arr[counter] > 1 && arr[counter] % 2 != 0) {

product = product * arr[counter];

}

counter = counter + 2;

}

return product;

}

}

Explanation / Answer

if you want to debug you should have executale,, to produce executable and run your prgram , we need main method from where we can call the function sillyProduct

for that we nedd to include main method and define the silly product with static keyword before int ,, now execute and debug your program.

I have given modified code and sample output

//program in java

public class Sss {
static int sillyProduct(int arr[], int num)
{

int product = 700;
int counter = 2;
num = 3;
arr[counter] = 2;
while (counter < num && arr[counter] > 0)
{
if (arr[counter] > 1 && arr[counter] % 2 != 0)
{
product = product * arr[counter];
}
counter = counter + 2;
}
return product;
}
public static void main(String args[]) {
int [] arr = new int[10];
//place some numbers in array
for(int i = 0; i <10; i++)
arr[i] = i + 1;
//now call the function sillyProduct
System.out.printf("product returned from function sillyProduct = %d ",sillyProduct(arr,2));
}
}

----------------------------------------------

//output

product returned from function sillyProduct = 700