This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiplication

 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem is k is not incrementing..

Ask yourself, where did I declare k ? And where did I initialize it ?
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sandeep Talari:
//problem is k is not incrementing..[/QB]


Also why have 2 counters = i and k?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12199
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic