Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to execute the program (no compilation error)

 
Alexie Chong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear experts,

I am doing my assignment on finding how many numbers in N digit satisfy K requirement.
However, when i am testing the code, i could compile it but i couldn't execute it.
I am wondering if i made mistake in the as when i comment this out, my program is able to execute,though i didn't get the right output value
Please kindly enlighten me.

Logic of my codes (example):

N = 15, K = 3

When N = 1, result = 0 + (N%10)
= 0 + (1%10)
= 1

y = N/10
= 1/10
= 0

x = 1 + 0
= 1
return x = 1

if (sumOfDigits(1) == K)
noOfNoSatisfy ++;
----------------------------------------------------
In the case of above, noOfSatisfy still remains as 0
-----------------------------------------------------
When N = 12, result = 0 + (N%10)
= 0 + (12%10)
= 2

y = N/10
= 12/10
= 1

x = 1 + 2
= 3
return x = 3

if (sumOfDigits(3) == K)
noOfNoSatisfy ++;

----------------------------------------------------
In the case of above, noOfSatisfy increase and plus 1
-----------------------------------------------------

 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What goes wrong when you try that code? You have to tell us the full details, otherwise we can't help.
 
Alexie Chong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used to have issue in getting the desired output which i want. Then i realized i made a mistake with the algorithim and have worked it out just fine.
Thanks so much for helping anyway
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what was the error?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic