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

1. Write a static method that takes an array of integers as a parameter and retu

ID: 3813296 • Letter: 1

Question

1. Write a static method that takes an array of integers as a parameter and returns true if the count of strictly positive values is larger than the count of strictly negative values in the array, false otherwise. A number is strictly positive if it is strictly larger than zero (i.e. it cannot equal zero). A number is strictly negative if it is strictly less than zero. 2. Write a static method that takes an array of integers as a parameter and returns back an integer that is the sum of all of the integers in the array. 3. What does the array list myInts contain at the end of this code segment? 1 Array List Integer myInts new Array List Integer 2 int temp 1; 4 for int i 1; i 10 it my Ints add (temp) temp temp i; 9 myInts remove (0) 10 my Ints. remove (2 4. What does this method do? In one short English sentence describe the task accomplished by this method. public static ArrayList

Explanation / Answer

Solution for 1st Question (JAVA):-

Program:-

import java.util.Scanner;
class List
{
   public void arrayList()
   {
       int size;
       System.out.println("Enter size of the array ");
       Scanner in=new Scanner(System.in);
       size=in.nextInt();
       int array[]=new int[size];
       System.out.println("Enter values into array");
       for(int i=0;i<size;i++)
       {
           array[i]=in.nextInt();
       }
       boolean val=findList(array);
       System.out.println(val);
   }
   public static boolean findList(int[] list)
   {
       int negative=0,positive=0;
       for(int i=0;i<list.length;i++)
       {
           if(list[i]>0)
           {
               positive++;
           }
           else if(list[i]<0)
           {
               negative++;
           }
       }
       if(positive>negative)
       {
           return true;
       }
       else
       {
           return false;
       }
   }
  
}
class FinalArray
{
   public static void main(String args[])
   {
       List b=new List();
       b.arrayList();
   }
}

Samle Output1:-

D:java>java FinalArray
Enter size of the array
5
Enter values into array
2 -5 4 -1 8
true

Sample Output2:-

D:java>java FinalArray
Enter size of the array
6
Enter values into array
-1 2 -4 5 -1 -22
false

Solution For 2nd Problem(JAVA):-

Program:-

import java.util.Scanner;
class SumList
{
   public void arrayList()
   {
       int size;
       System.out.println("Enter size of the array ");
       Scanner in=new Scanner(System.in);
       size=in.nextInt();
       int array[]=new int[size];
       System.out.println("Enter values into array");
       for(int i=0;i<size;i++)
       {
           array[i]=in.nextInt();
       }
       long val=findList(array);
       System.out.println(val);
   }
   public static long findList(int[] list)
   {
       long sum=0;
       int negative=0,positive=0;
       for(int i=0;i<list.length;i++)
       {
           sum=sum+list[i];
       }
       return sum;
   }
}
class FinalSum
{
   public static void main(String args[])
   {
       SumList b=new SumList();
       b.arrayList();
   }
}

Sample Output:-

D:java>java FinalSum
Enter size of the array
5
Enter values into array
2 5 8 7 9
31