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
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();
}
}
Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array...
Using Java. Write a program that creates a “triangular” two-dimensional array A of 10 rows. The first row has length 1, the second row has length 2, the third row has length 3, and so on. Then initialize the array using nested for loops so that the value of A[i][j] is i+j. Finally, print out the array in a nice triangular form.
in java eclipse, Create a program “FibonacciFifteen.java” and a method called “double[] getFibonacci()” that creates an array with a length of 15 that contains the first 15 numbers in the Fibonacci sequence and returns it. Set the first element to 0 and the second element to 1, then use a for loop to fill out the rest of the array by adding the prior two elements.
Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call
in java Write a program that uses recursion to find the largest number in an array. Declare and initialize an array of 10 different numbers.
Java Eclipse program Write statements to declare and initialize eight constants, one for each of the primitive types in Java. boolean, byte, char, short, int, long, float and double. Add statements to print the name of the constant and its value to your VariableDefinitions.javaprogram and compile the program. Assign a new value to one of the constants and compile. Comment out the lines of code that cause compilation errors but do not delete them and recompile your program.
Write a Java program that does the following. a. Declare an integer 2D array with 5 rows and 5 columns. b. Initialize the array's elements to random integers between 1 and 10 (inclusive). c. Display all the elements in the 2D array as a table of rows and columns. d. Display the row index and column index of all the even integers in the 2D array. e. Display the sum of first row's elements.
Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...
Write a JAVA program that declares and initializes an array with the following numbers: 10, 89, 50, 24, 60, 1, 15. Then ask the user for a number and check if the array contains that number. If it does, return a message to the user (print to screen) that says
JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...
In java, write method, shuffle, which accepts an array of int, creates a copy of the formal parameter, shuffles the copy, then returns the copied, shuffled array, leaving the formal parameter unchanged. Shuffling is a process of swapping each element of array with another element randomly chosen from the array. For testing the shuffle method have main call shuffle, repeatedly having it shuffle its previously returned array until the returned (shuffled) array is identical (equal) to the original array that...