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);
                

}
        }
    
}
}

You need to store the values that you are taking in from the keyboard into the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.