File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


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);
}//problem is k is not incrementing..
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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

Joined: Sep 13, 2007
Posts: 3132

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 OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

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:
subject: multiplication
It's not a secret anymore!