Chat with our AI personalities
int nearPalin(int n){ int temp = n; int count = 0; while(temp>0){ temp /= 10; count++; } if(count%2 == 0){ count = count/2; while(count--) n = n / 10; temp = n; while(n>0){ temp = temp*10 + n%10; n = n/10; } return temp; } else{ count = count/2; while(count--) n = n / 10; temp = n; n = n/10; while(n>0){ temp = temp*10 + n%10; n = n/10; } return temp; } }
If you're looking for 220 percent of some number n n * 2.2 = 220 percent of n n * x.yz = xyz percent of n In other words, just shift the decimal 2 places to the left for any problem like this.
Count it.
The average of n numbers = (sum of n numbers) / (count of n numbers).
class Sum_Of_Digits { public static void printSumandnoofdigits(int n) { int temp = n; int count = 0; int sum = 0; while ( n > 0 ) { sum = sum + n % 10; n = n / 10; count ++; } System.out.println("The number is..." + temp ); System.out.println("The sum of digits is..." + sum); System.out.println("The number of digits is..." + count); } }