This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 1958

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

Joined: Oct 02, 2003
Posts: 10908

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