Entering integers
Hi this is my first yr using java and I am so confice so I need some help.
I need to do a program where the user needs to input an integer of 3 digits but if the user enter less or greater then 3 digits the program needs to return an error message.
I need to do it with out using the command line for the output and input.
I hope some one can help me.
Thanks
[389 byte] By [
Maria81a] at [2007-11-26 20:41:37]

//This program needs to ask the user to how may 3 digits integer wants
//to enter and then send an error message if is less then or greater then
//3 digits and output the integers in ascending order.
//So this is what I have so far.
import javax.swing.*;
public class NumbersUp
{
public static void main(String args[])
{
String threeInt, error, num;
int threeDigits, counter = 1, number, ascSeq;
threeInt = JOptionPane.showInputDialog("Welcome!\n How many three digits integers you want to enter? ");
threeDigits = Integer.parseInt(threeInt);
if(args.lenght!=threeDigits)
error = JOptionPane.showInputDialog("Error: Please re-enter.");
else
{
int arrayLength = Integer.parseInt(args[0]);
int array[] = new int [arrayLenght];
int initialValue = Integer.parseInt(args[1]);
int increment = Integer.parseInt(args[2]);
for(int i=0; i<=array.lenght; i++)
array=initialValue+increment*i;
}
while(counter <= threeDigits)
{
num = JOptionPane.showInputDialog("Enter a three digit integer" + counter + ": ");
number = Integer.parseInt(num);
if ((num < 100) && (num > 999))
{
while()
{
ascSeq
}
}
else
{
JOptionPane.showMessageDialog(null, "Error: The interger must be 3 digits. \nPlease try again", "Invalid integer", JOptionPane.ERROR_MESSAGE);
}
JTextArea outputArea = new JTextArea(9, 9);
JScrollPane scroller = new JScrollPane(outputArea);
String ascendingSeq = String.format("The integers that you enter are has follows in a ascending sequence $%.2f.", number);
outputArea.setText(ascendingSeq);
JOptionPane.showMessageDialog(null, scroller, "Integers", JOptionPane.PLAIN_MESSAGE);
counter++;
}
}
}
Message was edited by:
Maria81
I'm pretty confused, you used args[] and JOptionPane in your program as input. Which is the real input?
In case you don't know what args is, it's the String array that follows your program name when you run it in command line.
> java myClass.class hello all
args[0] is hello
args[1] is all
Edit: if you use an IDE to compile and run, I think you don't get a chance to input the args.
Message was edited by:
Icycool