Java Applet with arrays

I'm trying to get real numbers entered from user (max 20) and put them in an array to sort ascending and descending also to find the mean, median, and range.  I know how to do all that, I just can't figure out how to put the numbers entered into the array.  thanks for any help

Wesmk
wesmkAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
Use a BufferedReader object to read the numbers as strings and then convert them to floating-point values using the methods in the Float class.

import java.io.* ;
import java.util.* ;

class MyClass
{
  public static void main ( String args[] )
    throws Exception
  {
    BufferedReader br = new BufferedReader ( new InputStreamReader ( System.in ) ) ;
    float array[] = new float[16] ;
    int i ;

    for ( i = 0 ; i < 16 ; i ++ )
        array[i] = Float.parseFloat ( br.readLine () ) ; // end for

    System.out.println ( "\n The values are..\n " ) ;

    for ( i = 0 ; i < 16 ; i ++ )
      System.out.println ( array[i] ) ; // end for

  } // end of main ()

} // clas definition over

That'll do it.

Mayank.
0
 
Peter KwanCommented:
Which kinds of user interface below does your application fit?

a) java YourApp 1 2 3 ...
b) java YourApp
Enter numbers: 1 2 3
c) GUI based, that means you have used AWT (or Swing) to handle user's input?

Thanks.
0
 
Peter KwanCommented:
Oops, sorry I overlook the title.

I assume you are using TextField (or JTextField) to allow users to enter the numbers. (Please correct me if i am wrong.)

Then the following code may help to solve your problem:

TextField userInputField = new TextField();
String numbers = userInputField.getText();
StringTokenizer tokens = new StringTokenizer(numbers);
float numbersArray[20];
int i=0;
while (tokens.hasMoreTokens())
    numbersArray[i] = Float.parseFloat(tokens.nextToken());

Hope this helps.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Mayank SAssociate Director - Product EngineeringCommented:
OOOOOOOOOOOoooooooooopppppppppppppppps!! I overlooked the title too! But hope my code helps you, man! You can just put a few modifications like instead of br.readLine (), read it from the text-field as myTextField.getText (). Keep one text-field and a submit button. Enter the value in the text-field and then click the button. When the button is pressed (in the actionPerformed () method), read the value from the text-field as I've told.

Mayank.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I see that you've posted this question again on the 12th. I've sent you a code-fragment there.

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20548427.html

Mayank.
0
 
CleanupPingCommented:
wesmk:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to mayankeagle

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Please go ahead with that recommendation.
0
All Courses

From novice to tech pro — start learning today.