10 Replies - 2048 Views - Last Post: 19 July 2009 - 10:57 PM Rate Topic: -----

#1 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

a little help here at Multiplication table

Posted 15 July 2009 - 10:49 PM

Here's my code

public class MultiplicationTabs{

	public static void main(String[]args)throws IOException {
		 BufferedReader kd=  new BufferedReader(new InputStreamReader( System.in ));
	 
	int num  = 0;
	System.out.print("Size of Multiplication Table: ");
	int size =Integer.parseInt(kd.readLine());
	System.out.println("Multiplication table of size: " +size);
	  for (int t = 0; t<= size; t++){
		if( t==0)
			System.out.print("\n");
	   
	  }	
	  for (int i = 1; i<=size; i++){
	   
		  System.out.print("\n ");
	  
	  
		  for (int k = 1; k<=size; k++){
			 num = i*k;
			 System.out.print(" " + num);
		   
			 }

		 
	  
	  
}
}
}



my problem is how could i control the output of my multplication table

the output should be like this.
Multiplication table of size: 5

	 1 2 3 4 5
 1  1 
 2  2 4 
 3  3 6 9 
 4  4 8 12 16 
 5  5 10 15 20 25
Process completed.



diagonal lining.

This post has been edited by NoobProgramer: 15 July 2009 - 10:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: a little help here at Multiplication table

#2 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

Re: a little help here at Multiplication table

Posted 16 July 2009 - 05:59 AM

BUMP.
need some help here please.
Was This Post Helpful? 0
  • +
  • -

#3 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2668
  • View blog
  • Posts: 15,703
  • Joined: 24-September 08

Re: a little help here at Multiplication table

Posted 16 July 2009 - 07:06 AM

Please don't do that.

So what exactly are you trying to do? Hide all the numbers above the squares?
Was This Post Helpful? 0
  • +
  • -

#4 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

Re: a little help here at Multiplication table

Posted 16 July 2009 - 06:53 PM

View PostNeoTifa, on 16 Jul, 2009 - 06:06 AM, said:

Please don't do that.

So what exactly are you trying to do? Hide all the numbers above the squares?


Like at the example i gave for output

it will control the flow of the numbers diagonally
Like what you have seen at my sample output
Multiplication table of size: 5

   1  2  3  4  5
1  1
2  2  4
3  3  6  9
4  4  8  12  16
5  5  10  15  20  25



This post has been edited by NoobProgramer: 16 July 2009 - 06:54 PM

Was This Post Helpful? 0
  • +
  • -

#5 malerv  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 100
  • Joined: 01-July 09

Re: a little help here at Multiplication table

Posted 16 July 2009 - 07:10 PM

Hint, the second for should not go from 1 to size ...
Was This Post Helpful? 0
  • +
  • -

#6 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

Re: a little help here at Multiplication table

Posted 16 July 2009 - 11:26 PM

my New Code

import java.io.*;
public class MultiplicationTabs{

	public static void main(String[]args)throws IOException {
		 BufferedReader kd=  new BufferedReader(new InputStreamReader( System.in ));
	 
	int num  = 0;
	System.out.print("Size of Multiplication Table: ");
	int size =Integer.parseInt(kd.readLine());
	System.out.println("Multiplication table of size: " +size);
	  for (int x= 1;x<= size; x++){
		  System.out.print(x+"  ");
	  
	  }

	  for (int i = 1; i<=size; i++){
	   
		  System.out.print("\n");
		  
	  
	  
		  for (int k = 1; k<=size; k++){
			 num = i*k;
			 System.out.print(num+"  ");
			 
			 }

		 
	  
	  
}
}
}



the output was
Size of Multiplication Table: 5
Multiplication table of size: 5
1  2  3  4  5  
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  
Process completed.



my problem is how can i add another 1-5 numbers at the
side of it and control or hide the other numbers
the ouput needed is kinda like this :wub:
	1  2   3   4   5
1  1
2  2  4
3  3  6   9 
4  4  8  12  16
5  5 10  15 20 25



This post has been edited by NoobProgramer: 16 July 2009 - 11:27 PM

Was This Post Helpful? 0
  • +
  • -

#7 Krysis09  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 25-April 09

Re: a little help here at Multiplication table

Posted 16 July 2009 - 11:58 PM

public class MultiplicationTabs
{

	public static void main(String[]args)throws IOException 
	{
		 BufferedReader kd=  new BufferedReader(new InputStreamReader( System.in ));
	 
		int num  = 0;
		System.out.print("Size of Multiplication Table: ");
		int size =Integer.parseInt(kd.readLine());
		System.out.println("Multiplication table of size: " + size);
		
		for(int i = 1; i < size+?; i++)
		{
			System.out.print("\t" + i);
		}
		System.out.println();
		  for (int i = 1; i < size+?; i++)
		  {
			System.out.print(i + "\t");
		  for (int k = ?; k <= ?; k++)
		  {
			 num = i*k;
			 System.out.print(num + "\t");		   
		  }
		  System.out.println();
		}
	}
}


Should work the way you wanted... so long as you can fill in the "?'s".

P.s. None of the ?'s are == size.
Was This Post Helpful? 0
  • +
  • -

#8 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

Re: a little help here at Multiplication table

Posted 17 July 2009 - 01:40 AM

int num  = 0;
		System.out.print("Size of Multiplication Table: ");
		int size =Integer.parseInt(kd.readLine());
		System.out.println("Multiplication table of size: " + size);
	   
		for(int i = 1; i < size+?; i++)
		{
			System.out.print(i + "\t");
		}
		System.out.println();
		  for (int i = 1; i <= size+?; i++)
		  {
		  System.out.print(i + "\t");
		  for (int k = 1; k <= i; k++)
		  {
			 num = k*i;
			 System.out.print(num + "\t");		  
		  }
		  System.out.println();
		}
	}
}



oh here's my edited new code
kindly check if its working
because im home now
i dont have jdk at home T_T

if it gets the output i needed.
this is it.
  1 2 3 4 5
1 1 
2 2 4
3 3  6  9
4 4  8  12 14 
5 5 10 15 20 25


This post has been edited by NoobProgramer: 17 July 2009 - 02:04 AM

Was This Post Helpful? 0
  • +
  • -

#9 Krysis09  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 25-April 09

Re: a little help here at Multiplication table

Posted 17 July 2009 - 08:28 AM

It's not quite what you're looking for... almost though. Your output (after I replaced the ?s with 1s:

Size of Multiplication Table: 5
Multiplication table of size: 5
1   2   3   4   5   
1   1   
2   2   4   
3   3   6   9   
4   4   8   12  16  
5   5   10  15  20  25  
6   6   12  18  24  30  36  

Process completed.


As you can see, one of the loops is going 1 too many times (size+1) and that you need to add a tab ("\t") before the first line reading: "1 2 3 4 5", so that your other numbers will line up correctly.

Hope that fixes it.
Was This Post Helpful? 0
  • +
  • -

#10 NoobKnight  Icon User is offline

  • D.I.C Head

Reputation: 49
  • View blog
  • Posts: 238
  • Joined: 14-July 09

Re: a little help here at Multiplication table

Posted 17 July 2009 - 09:02 AM

Here's another solution with printf. :)


	public static void main(String[] args) {
		int Outer_loop=5;
		int Inner_loop=0;
		
		for(int i=1; i<Outer_loop+1; i++)
		{
			System.out.print(i + ": ");
			for(Inner_loop=0; Inner_loop<i; Inner_loop++)
			{
				System.out.printf("%3d ", i*(Inner_loop+1));
			}
			System.out.println("");
		}
	}



1:   1 
2:   2   4 
3:   3   6   9 
4:   4   8  12  16 
5:   5  10  15  20  25 


Edited output...

This post has been edited by NoobKnight: 17 July 2009 - 09:10 AM

Was This Post Helpful? 0
  • +
  • -

#11 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

Re: a little help here at Multiplication table

Posted 19 July 2009 - 10:57 PM

Thank you
i already fixed it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1