• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

multiplication  RSS feed

 
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..
 
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 ?
 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • 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?
 
lowercase baba
Bartender
Posts: 12628
50
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!