[IN JAVA]
Copy the following code into your main.cpp and complete it
public class Main
{
public static void main(String [] args)
{
int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65};
int numElements = 10;
System.out.println("Part 1");
// Part 1
// Enter the statement to print the numbers in index 5 and index 8
// put a space in between the two numbers and a new line at the end
// Enter the statement to print the numbers 8 and 53 from the array above
// put a space in betwaeen the two numbers and a new line at the end.
// Enter the statement to change the number 2 in the array to be 12
// then write the statement to print out that number in the array
// and a new line at the end
System.out.println("Part 2");
// Part 2
// Write the loop to print out all of the numbers in the array
// Use the variables declared above (you might have to declare
// another variable) Put a space between each number
System.out.println("\nPart 3");
// Part 3
// Write the loop to print out all of the EVEN numbers in the array
// Use the variables declared above (you might have to declare
// another variable) Put a space between each number.
System.out.println("\nPart 4");
// Part 4
// Write a function called computeTotal that has the array
// and the number of elements passed into it. It will return
// the total of all of the numbers in the array
int total;
// Call the function you just wrote and store the answer
// in the varable total declared above
// This will print the total out
System.out.println(total);
}
}Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Main.java
public class Main
{
public static void main(String [] args)
{
int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65};
int numElements = 10;
System.out.println("Part 1");
// Part 1
// Enter the statement to print the numbers in index 5 and index
8
// put a space in between the two numbers and a new line at the
end
System.out.println(array1[5]+" "+array1[8]);
// Enter the statement to print the numbers 8 and 53 from the
array above
// put a space in betwaeen the two numbers and a new line at the
end.
System.out.println(array1[1]+" "+array1[6]);
// Enter the statement to change the number 2 in the array to be
12
// then write the statement to print out that number in the
array
// and a new line at the end
array1[4]=12;
System.out.println(array1[4]);
System.out.println("Part 2");
// Part 2
// Write the loop to print out all of the numbers in the
array
// Use the variables declared above (you might have to
declare
// another variable) Put a space between each number
for(int i=0;i<numElements;i++)
{
System.out.print(array1[i]+" ");
}
System.out.println();
System.out.println("\nPart 3");
// Part 3
// Write the loop to print out all of the EVEN numbers in the
array
// Use the variables declared above (you might have to
declare
// another variable) Put a space between each number.
for(int i=0;i<numElements;i++)
{
if(array1[i]%2==0)
System.out.print(array1[i]+" ");
}
System.out.println();
System.out.println("\nPart 4");
// Part 4
// Write a function called computeTotal that has the array
// and the number of elements passed into it. It will return
// the total of all of the numbers in the array
int total;
// Call the function you just wrote and store the answer
// in the varable total declared above
total=computeTotal(array1,numElements);
// This will print the total out
System.out.println(total);
}
private static int computeTotal(int[] array1, int
numElements) {
int sum=0;
for(int
i=0;i<numElements;i++)
{
sum+=array1[i];
}
return sum;
}
}
________________________
output:
Part 1
46 24
8 53
12
Part 2
5 8 34 7 12 46 53 12 24 65
Part 3
8 34 12 46 12 24
Part 4
266
_______________Could you plz rate me well.Thank
You
[IN JAVA] Copy the following code into your main.cpp and complete it public class Main { pub...
17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17}; int numElements = 11; cout << "Part 1" << endl; // Part 1 // Enter the statement to print the numbers in index 4 and index 9 // put a space in between the two numbers cout << endl; // Enter the statement to print the numbers 3 and 80...
This is for a java program public class Calculation { public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object //Task 1. Write your code here //Print the prompt and ask the user to enter an...
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 ...
Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()
PLEASE ANSWER #5AND #6, THE ANSWER FOR #3 AND #4 ARE ALREADY PROVIDED!!! 3 .Using Java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort, and create and sort 1000 arrays of this size timing the run to get an average time to sort an array of this size. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates 1000 times....
JAVA Language public class ArraySkills { public static void main(String[] args) { // *********************** // For each item below you must code the solution. You may not use any of the // methods found in the Arrays class or the Collections classes // String[] myData; // 1. Instantiate the given array to hold 10 Strings. // 2. Add your name to the Array at index 0 and a friend's name to the Array at index 4 // 3. Move your...
[JAVA]
help
——————
ListArrayMain.java
——————-
public class ListArrayMain {
public static void main (String[] args) {
ListArray L1 = new ListArray(); // constructs the list L1
L1.InsertBegin(2);
L1.InsertBegin(3);
L1.InsertBegin(7);
L1.InsertBegin(15);
L1.InsertBegin(5);
L1.InsertEnd(666);
L1.InsertAfter(1000,7);
// Now, let's print out the array to verify the insertions
worked.
System.out.println("The items in the list are:");
for (int i = 0; i<= L1.lastCell; i++) {
System.out.println(L1.a[i]);
}
System.out.println("The last cell number is: " +
L1.lastCell);
}// end main
}
———————————-
ListArray.java
————————————
public class ListArray...
This is the contents of Lab11.java
import java.util.Scanner;
import java.io.*;
public class Lab11
{
public static void main(String args[]) throws IOException {
Scanner inFile = new Scanner(new File(args[0]));
Scanner keyboard = new Scanner(System.in);
TwoDArray array = new TwoDArray(inFile);
inFile.close();
int numRows = array.getNumRows();
int numCols = array.getNumCols();
int choice;
do {
System.out.println();
System.out.println("\t1. Find the number of rows in the 2D
array");
System.out.println("\t2. Find the number of columns in the 2D
array");
System.out.println("\t3. Find the sum of elements...
Java programming question: Here is the feedback I received "sort fails. Use Arrays class method to sort." The actual question: Write a program as follows: Declare a five element array of Strings. Use a for loop and keyboard input to populate the array with the names of five friends. Sort the array in alphabetical order. Use a foreach loop to print the sorted array of friends, all on one line. Sample Output (inputs in italics) Enter the names of five...
Given the following Java code: public static void main (String[] args) { int num; System.out.println("Enter a number"); num = scan.nextInt(); <-first input statement while (num != 0) { System.out.println ("The number is: " + num); System.out.println("Enter a number"); num = scan.nextInt(); } //End While } //End Module The first input statement shown above is called the: