Question

Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array...

Write a Java program in Eclipse. .

Write a Java program that:

1. Creates an array of 100 integers. Initialize the array to have all zeros.

2. Puts even numbers starting from 6 (excluding multiples of 12) into the first 50 slots of the array above. So numbers 6,8,10,14,16,18,20,22,26, etc. go into the first 50 positions in the array. Print the array.

3. Puts random numbers between 45 and 55 into the second 50 slots of the array above (second 50 positions). Print the array.

4. Shuffle the contents of the array. Print the array.

5. Find the average of all the numbers from the 50th index to the 100th index in the array. Which is the second half of the array.

6. Print the average to five decimal places of accuracy to the right of the decimal. Meaning something like this 12.34567

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts please comment.

Java   Program:
import java.util.Random;
public class Example{

    public static void main(String[] args) {
        int[] arr = new int[100];
        int total = 0,j;
       j=6;
       double sum=0,avg;

       for(int i=0;i<100;i++)

       {

        arr[i]=0;

        }
        for(int i=0; i<50;){
           if((j%12)!=0)
           {
               arr[i]=j;
               i++;
           }
           j=j+2;
        }
        for(int i=50; i<100; i++){
           arr[i]=new Random().nextInt((55 - 45) + 1) + 45;
        }
        for(int i=0; i<arr.length; i++){
           System.out.print(arr[i]+" ");
        }
        for(int i=50; i<arr.length; i++){
           sum=sum+arr[i];
        }
        avg=sum/50;
        System.out.println();
        System.out.println();
        System.out.format("average=%.5f", avg);
        System.out.println();
        System.out.println();
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT