1 Replies - 9996 Views - Last Post: 29 November 2010 - 04:40 PM Rate Topic: -----

#1 puresunshine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-November 10

Java Multiplication Table

Posted 29 November 2010 - 04:10 PM

Directions are:

Write a Java program that prints a multiplication table with M rows and N columns. In the program:

a). Declare two variables row and col for row and column numbers in the main( ) method.
B). Define a static method called mTable(int row, int col) which takes row and col values from the main( ) method (you did this as a HMWK) and print the M by N multiplication table.
c). In your main( ) method,

* first assign M=7, N=5 and call the mTable method;
* then assign M=1, N=9 and call the mTable method;
* lastly assign M=9, N=1 and call the mTable method

This is what I have:
public class mtable {
      public static void main(String[] args) {
          int m = 9;
          int n = 5;
          mTable(m,n);
    }


      public static void mTable (int row, int col){
          for (int i = 1; i <= row ; i++) {
          for (int j = 1; j <= col; j++) {

          System.out.print(i+ "x" +j+ "=" + i*j + "     ");
    }
          System.out.println();
}
}
}



I am not sure if this is what my professor is looking for, especially since no column or row titles print. PLEASE HELP ASAP!!

This post has been edited by macosxnerd101: 29 November 2010 - 04:18 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Java Multiplication Table

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10447
  • View blog
  • Posts: 38,692
  • Joined: 27-December 08

Re: Java Multiplication Table

Posted 29 November 2010 - 04:40 PM

That looks like what is being expected to me, save for these last two parts:

Quote

* then assign M=1, N=9 and call the mTable method;
* lastly assign M=9, N=1 and call the mTable method


As for the headers, you will have to clarify that with your instructor.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1