aspose file tools
The moose likes Beginning Java and the fly likes multiplication Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 14672
    
  11

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
Ranch Hand

Joined: Sep 13, 2007
Posts: 1222

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
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

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.


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: multiplication
 
Similar Threads
how assignement takes place
labeled loop, break and continue
ques
Interface Q
Static initialization