Related questions
The required Java code:
import java.util.Scanner;
public class TriangleArray
{
public static void dotPattern()
{
//inner loop
for (int i= 5; i>0 ; i--)
{
//outer loop
for (int j=1; j<=i; j++)
{
if(i==j)
System.out.print(i); // print number
else
//prints dot
System.out.print(".");
}
//put the next line after printing each line
System.out.println();
}
}
public static double arrayAverage()
{
double[] array = new double[10];
double sum=0;
Scanner in = new Scanner(System.in);
for(int i=0; i<10; i++) // read array
{
System.out.print("Input a number ("+(i+1)+"/10): ");
array[i]= in.nextDouble();
sum +=array[i];
}
System.out.print("Your array is = [");
for(int i=0; i<9; i++)
System.out.print(array[i]+","); // print array
System.out.println(array[9]+"]");
return (sum/10); // return average
}
public static void main(String[] args) {
dotPattern(); // call method to print dots
System.out.println("The average of the numbers in the array is "+arrayAverage());
}
}
Step by stepSolved in 2 steps with 1 images
- In JAVAarrow_forwardConsider an array that stores the following sequence of integers: 10, 15, 20, 25, 30 Write a Java method that returns the sum of the integers stored in the array. The array must be passed to the method as an argument.arrow_forwardWrite the program in java dont use AI or copy from anything just write the code in simple and follow the instructionsarrow_forward
- For Java. Create a program that can read N integer numbers, store them in an array and then use a method to calculate and return the average of all numbers. Refer to photo.arrow_forwardWrite a java program that prompts user for 10 numbers of any type and stores them in an array. Then print the following: All the values in the array. The sum of all values in the array. The average of all values in the array. The largest value in the array. The smallest value in the array. All the positive numbers in array. All the negative numbers in array. All the odd numbers in array. All the even numbers in array.arrow_forwardWrite a Java program to test if 25 appears as either the first or the last element of an array of integers. The size of the array must be greater than or equal to 2. Sample array1: 25 3 80 9 2Sample output: TrueSample array2: 5 13 7 19 8Sample output: Falsearrow_forward
- Create a Java program that will perform the following statements.Perform the following items in a continuous manner. The code solution for the next item will be basedon the code performed on the previous item.1. Create an ArrayList named "apostles" and add the following names to it: Juan, Pedro, Lucas,Judas, Mateo, Marcos and Simon.2. Print the size of the ArrayList to the standard output before and after adding the names.3. Use two methods to print the names in standard output.a. Using For loopb. Using Iterator4. Add the name "Philip" at the end, and add the name "Thomas" between the two names "Juan"and "Pedro".5. Remove the name "Judas" using its index position.6. Search the names "Marcos", "James" and "Judas" in the ArrayList "apostles"This part will display the following:Does "apostles" contains Marcos? _______ (it will return a Boolean result)Does "apostles" contains James? _______Does "apostles" contains Judas? _______7. Sort the names of the ArrayList in alphabetical order.8....arrow_forwardIn Javaarrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education