Question

In: Computer Science

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

  1. 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.
  1. Write code to go through the array and increase any number < 50 by 20.
  1. Write code to find the average of the given array.

Write code to print the given array backwards

Solutions

Expert Solution

public class Main
{
   public static void main(String[] args) {
      
       int[]array={90, 57, 34, 81, 59, 51, 99, 52, 78, 67};
       System.out.println("originalarray is : ");
       print(array);
       evenOdd(array);
       increase(array);
       average(array);
       backward(array);
   }
   static void print(int[] list)
   {
   for(int i=0;i<list.length;i++)
   {
   System.out.print(list[i]+" ");
   }
   }
  
   static void evenOdd(int[] list)
   {
   int[] even=new int[10];
   int[] odd=new int[10];
   int i1=0;
   int j=0;
  
   for(int i=0;i<list.length;i++)
   {
   if(list[i]%2==0)
   {
   even[i1++]=list[i];
     
   }
   if(list[i]%2==1)
   {
   odd[j++]=list[i];
     
   }
   }
   System.out.println("\nodd array is : ");
   print(odd);
   System.out.println("\neven array is : ");
   print(even);
  
   }
  
       static void increase(int[] list)
   {
   for(int i=0;i<list.length;i++)
   {
   if(list[i]<50)
   {
   list[i]+=20;
   }
   }
   System.out.println("\narray increase by 20 : ");
   print(list);
   }
      static void average(int[] list)
   {
   float sum=0;
   for(int i=0;i<list.length;i++)
   {
   sum=sum+list[i];
   }
   System.out.println("\naverage is : "+sum/list.length);
   }
   static void backward(int[] list)
   {
   System.out.println("backward array is : ");
   for(int i=list.length-1;i>=0;i--)
   {
   System.out.print(list[i]+" ");
   }
   }
  
}


Related Solutions

Exam 2 scores of the class are given below 80, 52, 69, 78, 34, 67, 99,...
Exam 2 scores of the class are given below 80, 52, 69, 78, 34, 67, 99, 76, 67, 56, 68, 78, 77, 79 What’s the mean? What’s the median? What’s the mode? What’s the variance? What’s the standard deviation? What’s the range? If Jake took a makeup exam and got a 84.8 from this exam, what is his z score? (use the mean and the standard deviation calculated in part a and e). What does this z score tell us...
Given the data set below 25 52 67 23 78 89 57 90 32 77 45...
Given the data set below 25 52 67 23 78 89 57 90 32 77 45 48 62 54 94 69 46 79 40 33 21 57 84 54 23 34 68 63 61 76 87 78 39 50 70 60 32 65 73 45 28 82 66 79 71 80 46 66 24 90 A)What is the probability of an impossible even? B) What is the probability of a certain event? C) find the approximate mean using the Frequency...
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...
Year Salary (A) Salary (B) 1 65 55 2 65 57 3 65 59 4 67...
Year Salary (A) Salary (B) 1 65 55 2 65 57 3 65 59 4 67 62 5 69 64 6 72 67 7 74 69 8 77 72 9 79 75 10 82 78 11 84 81 12 87 84 13 89 88 14 89 91 15 89 95 16 92 95 17 92 95 18 94 95 19 94 95 20 96 99 1. Economics assumes people are interested in their rational self interest. Suppose a person works...
The actual values for 12 periods (shown in order) are: (1) 45 (2) 52 (3) 48 (4) 59 (5) 55 (6) 54 (7) 64 (8) 59 (9) 72 (10) 66 (11) 67 (12) 78
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...
Please use javascript. Starting with an array containing the numbers 1 through 10, use filter, map...
Please use javascript. Starting with an array containing the numbers 1 through 10, use filter, map and reduce to produce the following. Use console.log to display the results. a. An array of odd numbers b. An array of numbers divisible by 2 or 5 c. An array of numbers divisible by 3 squared d. The sum of the following: square the numbers divisible by 5
The actual values for 12 periods (shown in order) are: (1) 45 (2) 52 (3) 48 (4) 59 (5) 55 (6) 57 (7) 64 (8) 63 (9) 72 (10) 66 (11) 73 (12) 73
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. The actual values for 12 periods...
The actual values for 12 periods (shown in order) are: (1) 45 (2) 52 (3) 48 (4) 59 (5) 55 (6) 54 (7) 64 (8) 58 (9) 67 (10) 66 (11) 70 (12) 76
Instructions The Data 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: 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 decimal places. Data The actual values for 12 periods (shown in order) are: (1) 45  (2) 52 (3) 48 (4) 59  (5) 55  (6) 54  (7)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT