Help with arrays tutorial program please!
Sup!
For my course i have to write a java program that will make you enter ten integers and it will then print out the smallest integer! The problem im having is that it works every time except for when i enter "10,9,8,7,6,5,4,3,2,1" And it will say that 5 is the smallest integer! Please can you guys help me out as to where im going wrong! Heres my code! Thanks!
import java.util.Scanner;
public class smallestValue
{
public static void main(String args[])
{
Scanner myKeyboard = new Scanner(System.in);
int[] numbers = new int[10];
System.out.println("Enter 10 numbers!");
for(int i =0;i<numbers.length;i++)
{
numbers[i] = myKeyboard.nextInt();
}
int smallestNumber = numbers[9];
for(int i =0;i<numbers.length;i++)
{
if(i<smallestNumber)
{
smallestNumber = numbers[i];
}
}
System.out.println("Smallest Number: "+smallestNumber);
}
}
Re: Help with arrays tutorial program please!
Perhaps this will make your life easier
System.out.println(Math.min(26.7, 52.4));
they bulit-in many math features
Re: Help with arrays tutorial program please!
Step through the program - write down on a piece of paper if you have to - and evaluate how the program flows, what the values are, etc....add some System.out.println statements in there so you can directly evaluate the value of a variable (hint: i != numbers[i] )
Re: Help with arrays tutorial program please!
Thanks! I'll give it another try!