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

Hello, I am trying to answer these questions but I can\'t even get them to run.

ID: 3565948 • Letter: H

Question

Hello,

I am trying to answer these questions but I can't even get them to run. Here are the questions:

22. What does this method do?

public int foo(int [] a){

int temp = 0;

for (int i = 0; i < a.length; i++)
{
if (a[i] == 5)
temp++;
}
return temp;
}

26. What does this method do?

    public boolean [] foo( String [] a){

       boolean [] temp = new boolean [a.length];

       for (int i = 0; i < a.length; i++)
       {
       if (a[i]. contains ("0"))
       temp[i] = true;
       else
       temp[i] = false;
       }
       return temp;
       }

These are the important questions I really want answered. But if you can explain what I am doing wrong in this code:

public class Assment8_Test {
   public static void main( String[] args)
   {
   public boolean [] foo( String [] a){

       boolean [] temp = new boolean [a.length];

       for (int i = 0; i < a.length; i++)
       {
       if (a[i]. contains ("0"))
       temp[i] = true;
       else
       temp[i] = false;
       }
       return temp;
       }
  
   }
      
}

Compile Error:

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


I would be extremely grateful if someone could answer why I am getting this error.

Thank you in advance, and please, no directing me other pay sites. Chegg has been working out perfectly so far.

Explanation / Answer

//Program1 counts number of 5's in array passed to function foo

Program 1:

package easystudy;

public class Test1
{
           public int foo(int [] a)
               {
                   int temp = 0;
                   for (int i = 0; i < a.length; i++)
                       {
                           if (a[i] == 5)
                                   temp++;
                       }
                   return temp;
               }
   public static void main(String[] args)
   {
       Test1 ts1=new Test1();
       int a[]={5,6,7,8,5};
       System.out.println("Number of fives :"+ts1.foo(a));
   }
}

Output:

Number of fives :2

//Program2 takes input array of strings and returns boolean array(initilizes true if string contains '0')

package easystudy;

public class Test1
{
   public boolean [] foo( String [] a){

   boolean [] temp = new boolean [a.length];

   for (int i = 0; i < a.length; i++)
   {
   if (a[i]. contains ("0"))
   temp[i] = true;
   else
   temp[i] = false;
   }
   return temp;
   }
   public static void main(String[] args)
   {
       Test1 ts1=new Test1();
       String a[]={"h20","01231","into"};
       boolean b[]= ts1.foo(a);
       for(int i=0;i<a.length;i++)
       {
           System.out.println("String '"+a[i]+"' contains digit 0:"+b[i]);
       }
   }
}

sample output:

String 'h20' contains digit 0:true
String '01231' contains digit 0:true
String 'into' contains digit 0:false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote