0

Hello, I am on an introduction to software development module. I need help creating an array, it doesn't have to be hugely complex only basic as it is at introductory level, but still I am finding it difficult, please can someone help it will be gratefully appreciated.

This is the program I need to create:
Write a program to read in 10 integers (input by user) and store them in an array. After all the integers have been input, the program should find and output the smallest value and it's position in the array.

Ok so, this is what I got so far. I'm sure a for loop and if statement is needed by I cannot get my head around it.

import java.util.*;
public class SmallestInArray {
    public static void main(String[] args) {
                
       	Scanner myKeyboard = new Scanner(System.in);
        int [] numberArray = new int[10];
		System.out.println("\nType in 10 integers: ");
                
                int smallestSoFar;
                
                smallestSoFar = numberArray[0];             
                // initialise largest to 1st value 

    for (int i = 1; i < numberArray.length; i++)  
        {                                                    
     	 if (numberArray[i] > smallestSoFar) //if statement to check if new value is larger.
             
             {
		smallestSoFar = numberArray[i];      
                
                System.out.println(" smallest value is" + smallestSoFar);
                

}
        }
    
}
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by javaNooblet
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.