5 Replies - 9786 Views - Last Post: 21 July 2009 - 08:11 PM Rate Topic: -----

#1 metalloid   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 114
  • Joined: 11-September 08

Multiplication Table Using Swing

Posted 21 July 2009 - 05:56 PM

I need help with my assignment, we are instructed to make a multiplication table of 10's using swing. This is my code but I could not build it because there is an error on the last part.
import javax.swing.JOptionPane;

public class MT1
{
	public static void main (String args[]){
		String output ="";
		for (int x=1;x<=10;x++){
			for(int y=1;y<=x;y++)
				output +="x";
			output +="/n";
		}
		JOptionPane.showMessageDialog(null,"Result",JOptionPane.INFORMATION_MESSAGE);
		System.exit(0);
		}
	}



Is This A Good Question/Topic? 0
  • +

Replies To: Multiplication Table Using Swing

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Multiplication Table Using Swing

Posted 21 July 2009 - 06:26 PM

showMessageDialog takes 4 parameters
This will work

JOptionPane.showMessageDialog(null,output,"Result",JOptionPane.INFORMATION_MESSAGE);
Was This Post Helpful? 0
  • +
  • -

#3 metalloid   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 114
  • Joined: 11-September 08

Re: Multiplication Table Using Swing

Posted 21 July 2009 - 06:44 PM

I did the changes you commented and it did build, but there is another problem, the output was all x. How do I make the output to show numbers from 1-10?
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Multiplication Table Using Swing

Posted 21 July 2009 - 06:49 PM

what do you expect with a stament like

output +="x";

you propabley mean

output += " " + x;

:)

This post has been edited by pbl: 21 July 2009 - 06:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 metalloid   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 114
  • Joined: 11-September 08

Re: Multiplication Table Using Swing

Posted 21 July 2009 - 07:10 PM

There is the numbers 1-10 now. But the table is not complete. Here is my code after I did the change you commented.
import javax.swing.JOptionPane;

public class MT1
{
	public static void main (String args[]){
		String output ="";
		int num;
		for (int x=1;x<=10;x++){
			for(int y=1;y<=x;y++)
				num=x*y;
				output += " " + x;
			output +=" " + y;
		}
		JOptionPane.showMessageDialog(null,output,"Result",JOptionPane.INFORMATION_MESSAGE);
		System.exit(0);
		}
	}


Was This Post Helpful? 0
  • +
  • -

#6 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Multiplication Table Using Swing

Posted 21 July 2009 - 08:11 PM

Just put a System.out.println(output); whenever you change output
And you didn't add the num you calculated

I guess you want

output += " * " + x + "=" + num;

and you probably want to add a \n after your second loop to change line

output += "\n";
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1