Java Integer Truncate truncate(int n, int smallestDigit, int biggestDigit)

Here you can find the source of truncate(int n, int smallestDigit, int biggestDigit)

Description

This returns a string from decimal digit smallestDigit to decimal digit biggest digit.

License

Open Source License

Declaration

public static String truncate(int n, int smallestDigit, int biggestDigit) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*ww  w  .j  av a 2s.c o m*/
     * This returns a string from decimal digit smallestDigit to decimal digit
     * biggest digit. Smallest digit is labeled 1, and the limits are
     * inclusive.
     */
    public static String truncate(int n, int smallestDigit, int biggestDigit) {
        int numDigits = biggestDigit - smallestDigit + 1;
        char[] result = new char[numDigits];
        for (int j = 1; j < smallestDigit; j++) {
            n = n / 10;
        }
        for (int j = numDigits - 1; j >= 0; j--) {
            result[j] = Character.forDigit(n % 10, 10);
            n = n / 10;
        }
        return new String(result);
    }
}

Related

  1. truncate(int a, int b)
  2. truncate(int z, int base, int max)