Sunday, 15 July 2012

java - Nested statements unreachable code -



java - Nested statements unreachable code -

i writing programme , having hard time getting nested part correct. in method have ith digit number can fine if ith digit not in number have homecoming -1. when effort write in says code unreachable. have spent hours trying figure out. help appreciated.

public static int numdigits(int number) { int counter = 0; while(number !=0) { int digit = number % 10; number= number /10; counter++; } homecoming counter; } public static int getdigit(int number, int i) { int negative =0; int counter = 0; int digit = 0; while(counter < i) { digit = number % 10; number = number / 10; counter++; } homecoming digit; if(i>numdigits(number)) { negative = -1; } homecoming negative;

try code :

public static int numdigits(int number) { int counter = 0; while(number !=0) { int digit = number % 10; number= number /10; counter++; } homecoming counter; } public static int getdigit(int number, int i) { int negative =0; int counter = 0; int digit = 0; while(counter < i) { digit = number % 10; number = number / 10; counter++; } if(i>numdigits(number)) { negative = -1; homecoming negative; } homecoming digit; }

java nested

No comments:

Post a Comment