# arrays

dylan
arrays
1 Answer(s)      6 years and 9 months ago
Posted in : Java Beginners
Write an application that reads user inputs and prints the largest and the smallest values in the group.
? Include a static method readIntegers() that:
o Reads a certain number of integers from the user
o Saves them in an array, and
o Returns the array
&#8195;
? Include a static method that:
o Has a parameter of integer array
o Finds the largest value in the array, and
o Returns the largest
? Include a static method that:
o Has a parameter of integer array
o Finds the smallest value in the array, and
o Returns the smallest
? The program will then read user inputs and finds the largest and the smallest values by using the above three methods.
? The program prints the largest and smallest with all the user inputs.

September 1, 2010 at 5:21 PM

Hi Friend,

Try the following code:

import java.util.*;
public class ArrayExamples{

int arr[]=new int[5];
Scanner input=new Scanner(System.in);
System.out.println("Enter numbers: ");
for(int i=0;i<arr.length;i++){
arr[i]=input.nextInt();
}
return arr;
}
public static int largestNo(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 int smallestNo(int arr[]){
int min=arr[0];
for (int i=1; i<arr.length; i++) {
if (arr[i]< min) {
min = arr[i];
}
}
return min;
}
public static void main(String[]args){
int largest=ArrayExamples.largestNo(arr);
int smallest=ArrayExamples.smallestNo(arr);
System.out.println("Largest No: "+largest);
System.out.println("Smallest No: "+smallest);
}
}

Thanks

arrays
arrays  using arrays in methods   Java use arrays in methods import java.util.*; class ArrayExample{ public static int getMaxValue(int[] arr){ int maxValue = arr[0]; for(int i=1;i < arr.length;i
arrays
Store a table with students and information (name, ID, password, crypted password, etc) in a multi-dimensional array "stud"  Arrays and Strings: Store a table with students and information (name, ID, password, crypted password
Arrays
Arrays   Hi I need help with the following exercises. Exercise 1: Write a Java application in which the user is prompted for the total number of integer values to be stored in an array. Initialize the array with random values
Arrays
called Rebel.java; 2.Create two arrays. One of them must store integer numbers... the numbers in the second array by 3; 7.Print out the contents of both arrays. 8.Swap
Arrays in java
Arrays in java  what is param array in java
java arrays
java arrays  i need a java program to store student details like id,name,addr,marks,average,total..using arrays..input data using scanner class and by using class, object and constructor
java arrays
java arrays  can i know how can we intilize the three dimentional arrays in java? and how can we assign thae values to that array
Java with Arrays
Java with Arrays  I was given the assignment to create two parallel arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the arrays. The input for the problem should be provided in a text
java arrays
java arrays  how do you write the code for multipliying 2 double arrays to be in a 3rd double array? here is my code: package employeepay; /** * * @author Owner */ public class Main { /** * @param args the command line
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
How to create arrays in JavaScript?
How to create arrays in JavaScript?  How to create arrays in JavaScript
create arrays in JavaScript
create arrays in JavaScript  How to create arrays in JavaScript
arrays in java - Java Beginners
arrays in java  Hi All, I have two arrays. in this two array some name are same. I want to merge those arrays into single. But while merging I want to delete duplicate entries. How merge those arrays. Thanks, mln15584
java; arrays - Java Beginners
java arrays example  How can you create a program, by using arrays and the output would be X. by using char or string.Thank you
Are arrays primitive data types?
Are arrays primitive data types?   Hi, Are arrays primitive data types? thanks   Hi, In Java, Arrays are objects. Identifier are some simple variable names which is defined as the value container. The type of value
What is javascript Arrays?
What is javascript Arrays?   Hi, I am learner of JavaScript. My question is that What is JavaScript Arrays ? How to Define the JavaScript arrays in you program. Please give an example show that i will try my self. Thanks
combine two arrays in php
combine two arrays in php  combine two arrays in php   \$newArray = array_combine(\$diff, \$pages_name['data']); foreach (\$newArray as \$data) { var_dump(\$data); exit('zzzzz'); echo \$data . '<br>