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 3 of 3

Thread: Help with school project

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

    Default Help with school project

    Hi, i´m new to this forum and to java as well, my name is Matti and are from Iceland

    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

    row 1: line number, row 2: odd number, and row 3: is sum of the numbers in row 2 1 - 1+3 - 1+3+5 and so on

    this is what i got so far:
    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 is the column 1: number 1 to 15
    			{
    				for(b=1; b <= a; b++) // here is were i fail, column 2: odd numbers 1 to 29 
    				{
    				if( b % 2 != 0) // and after this i need column 3: sum of the numbers in column 2
    				Ttafla.appendText("" + a + '\t' + b + '\n');
    				}
    			}
    			return true;
    		}
    		return false;
    	}
    }
    thanks and regards
    Matti


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

    Default Re: Help with school project

    this is what i got so far:
    Please post the output from the program and add some comments describing what is wrong with it.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    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: Help with school project

    solved
    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;
    	}
    }

Similar Threads

  1. [SOLVED] Why do I need more than 1 class? - School project help.
    By Kakihara in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 26th, 2012, 09:08 PM
  2. School Help
    By scot_stuf in forum Java Theory & Questions
    Replies: 4
    Last Post: September 22nd, 2012, 04:31 PM
  3. School Java Project Help (XML and links)
    By MC2170 in forum Java Theory & Questions
    Replies: 6
    Last Post: July 3rd, 2012, 08:44 AM
  4. School java project, completely stuck
    By John1818 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 18th, 2010, 04:10 AM
  5. school project
    By robin28 in forum Java Theory & Questions
    Replies: 13
    Last Post: November 12th, 2010, 09:11 AM