aspose file tools*
The moose likes Beginning Java and the fly likes multiplication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multiplication" Watch "multiplication" New topic
Author

multiplication

sandeep Talari
Ranch Hand

Joined: Dec 24, 2007
Posts: 63
what is the problem in this code
class ManageTables
{
public static void main(String[] args)
{
for(int i=0;i<11;i++)
{
int k =1;
int y=9;
int z =(y*k);
System.out.println("9"+" * "+k+" = "+z);
k++;
}
}
}//problem is k is not incrementing..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

problem is k is not incrementing..

Ask yourself, where did I declare k ? And where did I initialize it ?


[My Blog]
All roads lead to JavaRanch
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2596
    
    9

Originally posted by sandeep Talari:
//problem is k is not incrementing..[/QB]


Also why have 2 counters = i and k?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

an easy way to figure this out would be to pepper your code with println() statements. Each time you do ANYTHING to k, put in a print statement...


put in something like 'debug' so you know what to take out, and number each line so you can tell which is which in your output.

you will eventually learn cleaner ways to do this (with tools like log4j for example), but this works for simple programs - and often for complex ones too, in many cases.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiplication