?
Solved

Java Applet with arrays

Posted on 2003-03-10
9
Medium Priority
?
160 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:wesmk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 8109204
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
 
LVL 30

Accepted Solution

by:
Mayank S earned 80 total points
ID: 8109293
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
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 8109382
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Expert Comment

by:Mayank S
ID: 8109940
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8125561
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
 

Expert Comment

by:CleanupPing
ID: 9058795
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
 
LVL 35

Expert Comment

by:girionis
ID: 9700540
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 9701060
Please go ahead with that recommendation.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question