Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: for loop and arrays !

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Angry for loop and arrays !

    // HI all ..

    i trying to develop applet program,it contain 2 arrays

    first one "marks"

    second one "names"

    and i use 10 enteris

    now when we run program :-

    user enter first name in textField "t1" and press on button "store"

    then the first name store in array" name" in index 0 ..

    then : user enter the mark of first name in intField "i1" .. then the mark store in array 2 in index 0

    and when we finish enter 10 student information ..

    we use sort button to sort marks from small to large ..

    and the names sort too .. ( name and marks are printed in TextArea )





    NOW :

    i have problem in if statement and else .. and i cant make the Applet ,, i need if else statement ! and the for loop

    this is the code //

    /*
    PLEASE HELP ME
    */


    package arrays;
     
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    public class NewApplet extends java.applet.Applet implements ActionListener{
        TextField t1;
        Button b1,b2;
        IntField i1;
     
        TextArea k1;
     
     
     
        public void init() {
            t1=new TextField(50);
            i1=new IntField(50);
            b1=new Button("sort");
            b2=new Button("store");
     
    k1=new TextArea(20,20);
     
             b1.addActionListener(this);
              b2.addActionListener(this);
     
     
                add(b1); add(b2); add(t1); add(i1);
     
                add(k1);
     
        }
     
     
     
     
        public void actionPerformed(ActionEvent e) {
            Object cause = e.getSource();
     
     
            String x1=t1.getText();
            int x2=i1.getInt();
     
     
     
           if(cause==b1){
     
     
           }
     
    if(cause==b2){
     
    }}}
    Last edited by helloworld922; May 6th, 2010 at 03:22 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: for loop and arrays !

    help..... :s

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: for loop and arrays !

    Please be patient We're not online 24/7 constantly refreshing the page for questions to answer.

    Here's a simple algorithm for sorting an array:
    1. Start with index = 0
    2. for every element indexed after index,
    3. compare it with elements before index (going in order form 0...index).
    4. At the first item that is "larger" than that value (according to the compareTo() method), the item at index needs to be inserted before that item
    5. Repeat until index=length of items to be sorted

    If you need help understanding the grammer/syntax of Java, this site should help you to understand the basic ways you can control the flow of your program: Java nuts and bolts: flow

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: for loop and arrays !

    OK , Thanx

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: for loop and arrays !

    See what you can do with helloworlds algorithm and post back if you get stuck
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM
  2. 2 D arrays problem
    By Pulse_Irl in forum Collections and Generics
    Replies: 2
    Last Post: March 5th, 2010, 04:49 PM
  3. Arrays
    By mlan in forum Java Theory & Questions
    Replies: 2
    Last Post: February 26th, 2010, 10:23 AM
  4. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 05:27 PM
  5. 2d Arrays
    By mgutierrez19 in forum Collections and Generics
    Replies: 5
    Last Post: October 27th, 2009, 04:08 PM