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: 1, 4, 9, 16 sequence

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 1, 4, 9, 16 sequence

    i'm new to java and i'm trying to make number sequence with one TextArea and one Button, using '\n' and '\t'
    the result should look like this:
    1 1 1
    2 3 4
    3 5 9
    . . .
    . . .
    . . .
    15 29 225

    i got the first two columns but i need help with the third
    import java.applet.Applet;
    import java.awt.*;
     
    public class talnarod extends Applet
    {
    	TextArea Ttafla;
    	Button Bstart;
    	int i, a, b, c;
     
    	public void init()
    	{
    		Bstart = new Button("Start");
    		Ttafla = new TextArea(15,25);
     
    		this.add(Bstart);
    		this.add(Ttafla);
    	}
    	public boolean action(Event e, Object o)
    	{
    		if (e.target == Bstart)
    		{
    			for (a=1; a <= 15; a++) //here i set the length of the sequence 1 to 15
    			{
    				b = a+a-1; //odd numbers for second column
    				c = 1; //and here i need help !!!
    				Ttafla.appendText("" + a + '\t' + b + '\t' + c + '\n');
    			}
    			return true;
    		}
    		return false;
    	}
    }
    Last edited by mattisvan; March 15th, 2013 at 07:15 AM. Reason: [SOLVED]


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 1, 4, 9, 16 sequence

    i need help with the third
    What values go in the third column? How does the value relate to the row its on?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1, 4, 9, 16 sequence

    i think it's solved ?
    column3 starts at 0 before it enters the loop, than column3 + column2
    import java.applet.Applet;
    import java.awt.*;
     
     
    public class talnarod extends Applet
    {
     
    	TextArea Ttafla;
    	Button Bstart;
    	int a, b, c;
     
    	public void init()
    	{
     
    		Bstart = new Button("Start");
    		Ttafla = new TextArea(15,25);
     
    		this.add(Bstart);
    		this.add(Ttafla);
    	}
    	public boolean action(Event e, Object o)
    	{
    		if (e.target == Bstart)
    		{
    			c = 0;					
    			for (a=1; a <= 15; a++)		
    			{
    				b = a+a-1;				
    				c = c+b;				
     
    				Ttafla.appendText("" + a + '\t' + b + '\t' + c + '\n');
     
    			}
    			return true;
    		}
    		return false;
    	}
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 1, 4, 9, 16 sequence

    If its solved, please mark this thread as solved.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1, 4, 9, 16 sequence

    Quote Originally Posted by Norm View Post
    If its solved, please mark this thread as solved.
    how, were do i mark it as solved ?

    sorry, solved problem is solved

Similar Threads

  1. Fibonacci sequence
    By ssohpkc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 8th, 2013, 09:29 PM
  2. Snapshot sequence
    By AnilS23 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 13th, 2012, 08:35 AM
  3. Sequence Classification
    By SilentNite17 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 1st, 2012, 08:25 AM
  4. Sequence
    By r_james14 in forum Java Theory & Questions
    Replies: 2
    Last Post: April 8th, 2012, 10:05 PM
  5. The Fibonacci sequence
    By Ryuk_93 in forum Android Development
    Replies: 1
    Last Post: March 26th, 2012, 11:56 AM