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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 14687

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: 2229

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

Also why have 2 counters = i and k?

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11145

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
Similar Threads
how assignement takes place
Static initialization
Interface Q
labeled loop, break and continue