need help java multiplication table
the output should be
rows 5
column 5
1 2 3 4 5 =120
2 4 6 8 10 =3840
3 6 9 12 15 =29160
4 8 12 16 20 =122880
5 10 15 20 25 =375000
=120 =3840 =29160 =122880 =375000
it means getting the product of each row and each column
Code :
import javax.swing.*;
public class activity2
{
public static void main(String []args)
{
int r=Integer.parseInt(JOptionPane.showInputDialog(null,"rows"));
int c=Integer.parseInt(JOptionPane.showInputDialog(null,"cols"));
int table[][]= new int [r][c];
for(int i=0;i<=table.length-1;i++){
for(int j=0; j<=table[0].length-1;j++){
table [i][j]= (i+1)*(j+1);
if(table[i][j]<0)
System.out.print(table[i][j]+"\t");
else
if(table[i][j] >10 && table [i][j] <100)
System.out.print(table[i][j]+"\t");
else
System.out.print(table[i][j]+"\t");
}
System.out.println("");
}
}
}
Re: need help java multiplication table
Can you post the current output and describe what is wrong with it?
Please edit your code and add proper formatting. Statements should not all start in the first column. There should be indentations of 3-4 spaces for each level of nested logic within each pair of {}s.
Re: need help java multiplication table
output is
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Re: need help java multiplication table
The second part of my post asked:
Can you explain what is wrong with the output?
Please edit your code and add proper formatting. Statements should not all start in the first column. There should be indentations of 3-4 spaces for each level of nested logic within each pair of {}s.
Re: need help java multiplication table
my code is fine but i do not know how to get the product of each row and each column...like what i posted to my first post..
sorry about the indentions..
Re: need help java multiplication table
Start with the numbers on a row. Define a variable to hold the product. As each number for that row is created, include its value in the product for that row. After the last number for the row, print it.
When that code works, work on the logic for the columns. Best to do one at a time.
Re: need help java multiplication table
can you teach me how to do it??
Re: need help java multiplication table
Do the code for the rows first. See post#6 for ideas.
When that works, then work on the columns.
Re: need help java multiplication table
i have really no idea what will i code to hold the values of row 1
Re: need help java multiplication table
Outside the loop, define an int variable with initial value of 0
inside the loop add each number that is generated and printed to the variable
after the loop print the value of the variable at the end of the row.
You need to fix the formatting of your code if you want anyone to look at it.