loops - simple multiplication arrays in java -


i want create simple java program simple loops , arrays. should multiplication table.

if rows 3 , columns 5 then, should display rows, columns , inside matrix should give multiplication of row , column. output should this.

     1    2    3    4    5 1    1    2    3    4    5 2    2    4    6    8    10 3    3    6    9    12   15 

this want create simple loops. new java not able figure out how can this. kindly let me know.

i have done code till here.

import java.util.*;

class cross_multiplication {      public static void main(string a[])         {          system.out.println("how many rows required? : ");         scanner in1 = new scanner(system.in);         int num_rows = in1.nextint();          system.out.println("how many cols required? : ");         scanner in2 = new scanner(system.in);         int num_cols = in2.nextint();      //int arr1 [] = new int[num_rows];      //int arr2 [] = new int[num_cols];                for(int i=0;i<num_rows;i++)         {                 if (i==0)                 {                     system.out.print("");                 }                 else                 {                     system.out.print(i);                             }                 system.out.print("\t");               }       } } 

thanks

to include headers, need check whether in row 0 (j == 0) or column 0 (i == 0). example of how this:

public static void print(int x, int y) {   (int = 0; <= x; i++) {     (int j = 0; j <= y; j++) {       if(i==0) { // first row         if(j>0) {           system.out.printf("%d\t", j);         }         else { // first row, first column: blank space           system.out.printf("\t");         }       }       else {         if(j == 0) { // first column           system.out.printf("%d\t", i);          }         else { // in body of table - finally!           system.out.printf("%d\t" * j);         }       }     }     system.out.println();   } } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -