Results 1 to 2 of 2
Thread: Boolean value not resetting
- 03-30-2011, 02:51 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
Boolean value not resetting
I am working on a recursive call that checks to see if numbers are divisible by 10 and return false if not. I can't figure out why if(g != 0) ans = false; doesn't change the value of ans in the method and pass back false to the main method. Thank you for your help.
Java Code:public class MultiplesOfTen { public static boolean dividedBy10 (int x[], int r, int y, boolean ans){ int g = (x[r]%10); if(g != 0) ans = false; else if ( r < y){ r++; dividedBy10(x, r, y, ans); } return ans; } public static void main(String[] args) { int [] nums = {30,55,80,70,100}; int r = 0; //set for the index value int len = nums.length -1; boolean ans = true; System.out.print("Are all the numbers dividable by 10?"); System.out.println("The answer is: " + dividedBy10(nums, r, len, ans)); } }
- 03-30-2011, 03:28 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
use boolean as 0 or 1
By joost_m in forum New To JavaReplies: 10Last Post: 04-13-2010, 11:22 AM -
Boolean methods
By sonny in forum New To JavaReplies: 7Last Post: 03-26-2010, 10:16 PM -
Boolean problems
By Chasingxsuns in forum New To JavaReplies: 2Last Post: 09-15-2009, 10:57 PM -
transfer boolean to 1's and 0's
By Nikohw in forum Java AppletsReplies: 5Last Post: 09-12-2009, 09:05 PM -
Boolean Expression
By ritwik07 in forum New To JavaReplies: 3Last Post: 07-11-2007, 04:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks