posted 14 years ago
Hi Everyone;
First off I'd just like to say how great this website is. I've gotten lots of great advise and I appreciate it.
Well I need more advice. Below I have written a program that asks the user to input integers up to an array of 30 and then the output finds the smallest integer inputed. I've got all that working fine, what I don't have is the statement that says if the input is "0" it will jump to the result. I've tried working it a few different ways and I know I'm close but I can't seem to get it. Does anyone have any advise?? Please
public class Array5_3 {
public static void main(String [] args) {
int[] integers = new int[4];
for (int x = 0; x < integers.length; x++){
String input = JOptionPane.showInputDialog(null,
"Please enter a number, \nto return the smallest number enter 0.",
"Programming",JOptionPane.QUESTION_MESSAGE);
integers[x] = Integer.parseInt(input);
}
int small = integers[0];
for (int x = 0; x < integers.length; x++) {
if (small > integers[x])
small = integers[x];
}
JOptionPane.showMessageDialog(null, "The smallest integer inputed was "+ small,
"Programming", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
Thanks in advance
Stacey
First off I'd just like to say how great this website is. I've gotten lots of great advise and I appreciate it.
Well I need more advice. Below I have written a program that asks the user to input integers up to an array of 30 and then the output finds the smallest integer inputed. I've got all that working fine, what I don't have is the statement that says if the input is "0" it will jump to the result. I've tried working it a few different ways and I know I'm close but I can't seem to get it. Does anyone have any advise?? Please
public class Array5_3 {
public static void main(String [] args) {
int[] integers = new int[4];
for (int x = 0; x < integers.length; x++){
String input = JOptionPane.showInputDialog(null,
"Please enter a number, \nto return the smallest number enter 0.",
"Programming",JOptionPane.QUESTION_MESSAGE);
integers[x] = Integer.parseInt(input);
}
int small = integers[0];
for (int x = 0; x < integers.length; x++) {
if (small > integers[x])
small = integers[x];
}
JOptionPane.showMessageDialog(null, "The smallest integer inputed was "+ small,
"Programming", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
Thanks in advance
Stacey
posted 14 years ago
Also, in your code where you look for the smallest, you will need to exclude zero from being the smallest; otherwise, the answer will always be zero.
Alternatively, you could introduce an index variable and make it more than just a loop variable:
[ January 21, 2004: Message edited by: Joel McNary ]
Also, in your code where you look for the smallest, you will need to exclude zero from being the smallest; otherwise, the answer will always be zero.
Alternatively, you could introduce an index variable and make it more than just a loop variable:
[ January 21, 2004: Message edited by: Joel McNary ]
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
a fool thinks himself to be wise, but a wise man knows himself to be a fool  shakespeare. foolish tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
