Question

In: Computer Science

I am in beginners java course so using the most simple/basic JAVA please complete the following...

I am in beginners java course so using the most simple/basic JAVA please complete the following CODE SEGMENTS. (2 parts)

FIRST PART: Using ITERATIVE create a METHOD MAX that returns the max element in an ArrayList of ints and prints all of the elements. *you have to use an iterative in the method.* (just need to write the METHOD ONLY not a whole program(will do in 2nd part), assume you are given any numbers/integers.

SECOND PART: Now write a class MaxValue that uses a MAIN METHOD to prompts a user to input a series of integers(same numbers/ints will be used in both parts.). THEN CALL THE MAX METHOD USED IN PART ONE TO RETURN THE HIGHEST VALUE/INTEGER INPUTTED. Please show the complete work and use comments and write neatly!

Solutions

Expert Solution

SOURCE CODE

PART 1

public static int Max(int[] arr){
int max = arr[0];
for(int i=1;i < arr.length;i++){
if(arr[i] > max){
max = arr[i];
}
}
return max;
}

PART 2

import java.util.Scanner;
public class Max_Number
{
   public static int Max(int[] arr){
int max = arr[0];
for(int i=1;i < arr.length;i++){
if(arr[i] > max){
max = arr[i];
}
}
return max;
}
public static void main(String[] args)
{
int n, max;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int arr[] = new int[n];
System.out.println("Enter elements of array:");
for(int i = 0; i < n; i++)
{
arr[i] = s.nextInt();
}
  
max = Max(arr);
   System.out.println("Maximum Value is: "+max);
}
  
}

OUTPUT SCREENSHOT

please give a upvote if u feel helpful.


Related Solutions

Hello i am working on an assignment for my programming course in JAVA. The following is...
Hello i am working on an assignment for my programming course in JAVA. The following is the assignment: In main, first ask the user for their name, and read the name into a String variable. Then, using their name, ask for a temperature in farenheit, and read that value in. Calculate and print the equivalent celsius, with output something like Bob, your 32 degrees farenheit would be 0 degrees celsius Look up the celsius to farenheit conversion if you do...
I am using a photoshop character that I drew. Please provide AS SIMPLE OF A PROCEDURE...
I am using a photoshop character that I drew. Please provide AS SIMPLE OF A PROCEDURE AS POSSIBLE!! 1. How do you create a sprite in Unity? 2. How do you create a sprite sliced in Unity? Thank you :)
Write the basic JAVA code for the beginners and follow all the instructions listed 1. A...
Write the basic JAVA code for the beginners and follow all the instructions listed 1. A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for e.g., 1980), except that it is not a leap year if it is also divisible by 100 (for e.g., 1900); however, it is a leap year if it is further divisible by 400 (for e.g., 2000). Write a program that prompts the...
I am using a drawing done in my photoshop. Please provide a simple procedure for how...
I am using a drawing done in my photoshop. Please provide a simple procedure for how to do these tasks in UNITY. 1. How do you do an animation clip screenshot? 2. How do you show or do the animator screenshot layer?
Please create using only For loops, as simple as possible as I am attending Java1 Create...
Please create using only For loops, as simple as possible as I am attending Java1 Create two Java programs that do the following: a. Use a for loop to print the numbers below on a single line as shown. 1 2 4 8 16 32 64 128. b. Ask the user to enter numbers using the for loop.  First ask the user how many numbers they will be entering in. Print the sum and average of the entered numbers. c. Write...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand thanks! tree(root) node(value, leftchild,rightchild) method: insert(value)
IN JAVA: I am using binary and linear search methods in java. How can I Generate...
IN JAVA: I am using binary and linear search methods in java. How can I Generate a new array with 10000 elements, and initialize the elements to random values using Math.random() and how can i sort the array using Arrays.sort(). I just need examples, no exact code is necessary. The array must be of doubles.
I am using a course that requires me to use excel.I am able to figure everything...
I am using a course that requires me to use excel.I am able to figure everything out except the test statistic A marine biologist claims that the mean length of mature female pink seaperch is different in fall and winter. A sample of 15 mature female pink seaperch collected in fall has a mean length of 108 millimeters and a standard deviation of 15 millimeters. A sample of 8 mature female pink seaperch collected in winter has a mean length...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP i am getting an error messge a. Create a...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP i am getting an error messge a. Create a class named Sandwich. Data fields include a String for the main ingredient (such as tuna), a String for bread type (such as wheat), and a double for price (such as 4.99). Include methods to get and set values for each of these fields. Save the class as Sandwich.java. b. Create an application named TestSandwich that instantiates one Sandwich object and demonstrates the use of...
Hi I am getting error in implement some test case using Java. I am adding my...
Hi I am getting error in implement some test case using Java. I am adding my code and relevant files here, and the failed test. Please let me know where my problem is occuring and fix my code. Thanks! I will upvote. Implement a class to perform windowing of a Hounsfield value Implement the class described by this API. A partial implementation is provided for you in the eclipse project; however, unlike the previous class, very little work has been...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT