Publicidad
use integers not doubles- saves on data entry time when testing- (Find.docx
use integers not doubles- saves on data entry time when testing- (Find.docx
Próximo SlideShare
  Given below is a Java method min to get an integer array as a para.docx Given below is a Java method min to get an integer array as a para.docx
Cargando en ... 3
1 de 2
Publicidad

Más contenido relacionado

Más de kevin792(20)

Publicidad

use integers not doubles- saves on data entry time when testing- (Find.docx

  1. use integers not doubles- saves on data entry time when testing. (Find the smallest element) Write a method that finds the smallest element in an array of double values using the following header: public static double min(double[] array) Write a test program that prompts the user to enter ten numbers, invokes this method to return the minimum value, and displays the minimum value. Here is a sample run of the program: Solution import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static double min(double[] array){ // function to find the minimum double min = array[0]; // assigning 1st element as min for(int i=1;i<10;i++){ // looping through the elements of the array if(min > array[i]) // condition check for current min min = array[i]; } return min; // return min value } public static void main (String[] args) throws java.lang.Exception // main function for testing the min function { Scanner input = new Scanner(System.in); System.out.print("Enter ten numbers: "); double[] array = new double[10]; for(int i=0;i<10;i++){ // for loop for inputting 10 elements double temp = input.nextDouble(); // getting double values from the user array[i] = temp; } System.out.println("The minimum number is: "+min(array)); // invoking the min function and printing
  2. } } ---------------------------------------- output ---------------------------------------
Publicidad