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 :)
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)
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: 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.
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...
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...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.
I need this in java using textpad. I am missing a few lines where I added...
I need this in java using textpad. I am missing a few lines where I added in comments. I don't know what I need to add in. Here are the two programs as pasteable code.The comments in the code say what I need done. The two programs are below. I need it to work with the generic version of SLLNode. It is posted at the bottom. public class ListDemoHw { public static void printLinkedList(SLLNode node) { // display all elements...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT