import java.util.Arrays;
import java.util.Scanner;
public class ArrayPractice {
public static void main(String args[]){
double[] grades
={81.2,92.5,48.9,78.8,45.5};
int[] numbers ={12, 42, 33, 67, 92,
58,33};
String arguments[]=new
String[9];
System.out.println("Length of
grades: "+grades.length);
System.out.println("Length of
numbers: "+numbers.length);
System.out.println("Length of
arguments : "+arguments.length);
System.out.println("First element
of grades: "+grades[0]);
System.out.println("Third element
of grades: "+grades[3]);
System.out.println("Last element of
numbers of grades: "+numbers[numbers.length-1]);
//Set the second to last element of
grades to be 90.5.
grades[grades.length-2]=90.5;
//Set the third element of numbers
to be 99.
numbers[2]=99;
//Set the first six elements of
arguments to be "Java", and the rest to be "C++". (HINT: use a loop
or two)
for(int i=0;i<6;i++)
arguments[i]="Java";
for(int i=6;i<9;i++)
arguments[i]="C++";
//Use a loop to print each element
of grades on the same line, separated by commas (with a trailing
comma).
for(int
i=0;i<grades.length;i++)
System.out.print(grades[i]+" ");
System.out.println();
//Use a loop to print each element
of numbers on the same line, separated by spaces (with a trailing
space).
for(int
i=0;i<numbers.length;i++)
System.out.print(numbers[i]+" ");
System.out.println();
//Use a loop to print each element
of arguments on the same line, separated by an underscore (with a
trailing underscore).
for(int
i=0;i<arguments.length;i++)
System.out.print(arguments[i]+"_");
System.out.println();
//Print the contents of grades
using Arrays.toString(grades);
System.out.print(Arrays.toString(grades)+",");
System.out.println();
//Print the contents of numbers
using Arrays.toString(numbers);
System.out.print(Arrays.toString(numbers)+" ");
System.out.println();
//Print the contents of arguments
using Arrays.toString(arguments);
System.out.print(Arrays.toString(arguments)+"_");
System.out.println();
System.out.printf("Average of
grades: %.3f\n",arrayAverage(grades));
}
public static double arrayAverage(double
[]array)
{
double sum=0;
for(int
i=0;i<array.length;i++)
{
sum+=array[i];
}
return sum/array.length;
}
}
Create a new ArrayPractice project in Eclipse and a class named ArrayPractice.java. Put everything that follows...
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 simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...
put everything together in an object-oriented manner! create a class named PositiveNumberStatistics that has the following: A private double 1D array instance variable named numbers. A constructor that takes one parameter, a 1D double array. The constructor should throw an IllegalArgumentException with the message "Array length of zero" if the parameter has a length of 0. If the exception is not thrown, the constructor should create the numbers array and copy every element from the parameter into the numbers instance...
Create a java project. Create a class called cls2DarrayProcessor.java. with the following: Reads numbers from a pre-defined text file. A: Text file name should be data.txt B: Text file should be in the same workspace directory of your project's folder C: Text file name should be STORED in a String and called: String strFile ='./data.txt' Defines a 2-D array of integers with dimensions of 5 rows by 5 columns. Inserts the data from the text file to the 2-D array...
Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...
5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create a method called generateSuperLottoNumbers() that returns an array of 6 random SuperLotto lottery numbers. The first 5 numbers must be from the range 1 to 47 The 6th number (the MEGA) must be from 1 to 27. Create a method called printTicket() that takes an integer array as an parameter it will loop through the integer array and print out the data Display the...
C++ Program Int Main First Please Write one program that does the following: 1. 1. Ask the user for ten (10) grades, and store the data in an array. Compute the average of all the grades. Print the original ten grades and the average. a. Declare an integer array with the name of “grades” of size 10 in the main function. b. Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array. i. The function will receive...
Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6}; Declare an int called largestNum and set it to 0. Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); } Write a for loop that prints the array backwards ...
Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...