Question

In: Computer Science

Java: int[]array={-40 ,60 ,78 ,-51 ,65 ,-95 ,77 ,-48 ,-66 ,71}; 1)     Create two int arrays called...

Java:

int[]array={-40 ,60 ,78 ,-51 ,65 ,-95 ,77 ,-48 ,-66 ,71};

1)     Create two int arrays called negative and positive of length 10. Go through the given array and place the negative values into the array called negative and the positive values into the array called positive.

2)     Write code to find the smallest value in the given array and print the value out.

3)     Write code to find the largest value in the given array and print it out.

4)     Create an int array called flipped and reverse the sign of every number in the given array and place it in the flipped array.

Solutions

Expert Solution


public class list {

//THIS FUNCTION FINDS THE SMALLEST IN THE ARRAY AND RETURNS IT

public int smallest(int a[])
{
   int min=a[0];
   for(int i:a)
   {
       if(i<min)
       {
           min=i;
       }
   }
   return min;
}

//THIS FUNCTION FINDS THE LARGEST IN THE ARRAY AND RETURNS IT
public int largest(int a[])
{
   int max=a[0];
   for(int i:a)
   {
       if(i>max)
       {
           max=i;
       }
   }
   return max;
}

//THIS FUNCTION RETURNS THE FLIPPED ARRAY
public int[] flip(int a[])
{
   for(int i=0;i<a.length;i++)
   {
           a[i]=-a[i];          
   }
   return a;
}
public static void main(String[] args) {
   int array[]= {-40,60,78,-51,65,-95,77,-48,-66,71};
   int positive[]=new int[10];
   int negative[]=new int[10];
   int i=0,j=0;
   list l=new list();
   for(int a:array)
   {
       if(a>=0)
       {
           positive[i++]=a;
       }
       else
       {
           negative[j++]=a;
       }
      
   }

for(int p=0;p<i;p++)
   {
       System.out.print(positive[p]+" ");
   }
   System.out.println();
   for(int p=0;p<j;p++)
   {
       System.out.print(negative[p]+" ");
   }
   System.out.println();
   System.out.println(l.smallest(array));
   System.out.println(l.largest(array));
   int flipped[]=new int[10];
   flipped=l.flip(array);
   for(int p:flipped)
   {
       System.out.print(p+" ");
   }

}
}

HERE IS CODE FOR ABOVE QUESTIONS

1) IMPLEMENTED IN MAIN ITSELF

2)WRITTEN SEPARATE FUNCTION

3)WRITTEN SEARATE FUNCTION

4)WRITTEN A SEPARATE FUNCTION

PLEASE UPVOTE IF U LIKE MY ANSWER AND WRITE IN COMMENTS IF U HAVE ANY DOUBTS


Related Solutions

int[]array={-40 ,60 ,78 ,-51 ,65 ,-95 ,77 ,-48 ,-66 ,71}; Create two int arrays called negative...
int[]array={-40 ,60 ,78 ,-51 ,65 ,-95 ,77 ,-48 ,-66 ,71}; Create two int arrays called negative and positive of length 10. Go through the given array and place the negative values into the array called negative and the positive values into the array called positive. Write code to find the smallest value in the given array and print the value out. Write code to find the largest value in the given array and print it out. Create an int array...
25 49 66 44 60 36 51 78 41 54 32 54 80 56 48 41...
25 49 66 44 60 36 51 78 41 54 32 54 80 56 48 41 65 64 62 53 47 72 39 69 44 1) Average 2) Medium 3) Q1 4) Q3 5) P63 6) P93 7) Range 8) Variance 9) Standard Deviation 10) Construct a box-mustache graph for the above data.
46 42 37 52 58 36 75 72 90 65 78 80 56 40 48 60...
46 42 37 52 58 36 75 72 90 65 78 80 56 40 48 60 58 76 82 75 38 48 86 88 75 65 45 80 68 47 62 75 56 85 44 70 75 64 67 72 For the data set distribution of Salaries of the employees                                               Arrange in an array (ascending order) Evaluate the mean, the median, the mode, the skew, the average deviation the standard deviation and the interquartile range. Group, on a new...
int[]array={90, 57, 34, 81, 59, 51, 99, 52, 78, 67}; use for numbers 1 through 4...
int[]array={90, 57, 34, 81, 59, 51, 99, 52, 78, 67}; use for numbers 1 through 4 Write code to create two int arrays called odd and even of length 10. Populate the arrays with even numbers in the even array and odd numbers in the odd array as you go through the int[]array [ reminder 7%2 is 1, 8%2 is 0. The modulus operator yields the remainder]. Do not worry about the 0’s that are not filled. Write code to...
3. Array Operations 3-1 Write a function, equalsArray that when passed two int arrays of the...
3. Array Operations 3-1 Write a function, equalsArray that when passed two int arrays of the same length that is greater than 0 will return true if every number in the first array is equal to the number at the same index in the second array. If the length of the arrays is less than 1 the function must return false. For example, comparing the two arrays, {1,2,3,4,5} and {1,2,3,4,5} would return true but the two arrays {3,7} and {3,6}...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name...
In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name and print it out. 2) Create an uninitialized char array and copy into it      the char array containing your full name and print it out. 3) Create a Character array and copy into it the char array containing      your full name and print it out. 4) Into the Character array, use toUpperCase() to copy the char array containing     your full name...
1.Write the java code to create a two dimensional String array of sizes 12 by 8;...
1.Write the java code to create a two dimensional String array of sizes 12 by 8; Given the java array:       double[] test = new double[3]; 2.  Write the java code to put the numbers 1.0, 2.0, and 3.0 in to the array so that the 1.0 goes in the first cell, the 2.0 goes in the second cell and the 3.0 goes in the third cell. 3. Can you have different types of data is a three dimensional array? 4....
The actual values for 12 periods (shown in order) are: (1) 45 (2) 52 (3) 48 (4) 59 (5) 55 (6) 58 (7) 64 (8) 61 (9) 71 (10) 66 (11) 69 (12) 77
Question 1 contains the actual values for 12 periods (listed in order, 1-12). In Excel, create forecasts for periods 6-13 using each of the following methods: 5 period simple moving average; 4 period weighted moving average (0.63, 0.26, 0.08, 0.03); exponential smoothing (alpha = 0.23 and the forecast for period 5 = 53); linear regression with the equation based on all 12 periods; and quadratic regression with the equation based on all 12 periods. Round all numerical answers to two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT