Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3441356
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:32:35+00:00 2026-05-18T08:32:35+00:00

I have the next code, which gets a number, I need to split that

  • 0

I have the next code, which gets a number, I need to split that number in to parts, firstPart should be the whole number without the last digit, and the secondPart should be only the last digit of the original number.

public Boolean verificationNumberFiscalId(String fiscalId) {

        // Trying to do a better wa yto do it
        Integer firstPart = fiscalId.length()-1;
        Integer secondPart = ??????????;



        // My old logic
        String NitValue = "";
        for (Integer i = 0; i < fiscalId.length()-1; i++) {
            NitValue = fiscalId.substring(i,1);
        }

        Integer actualValueLength = fiscalId.length()-1;        
        String digitoVerificador = fiscalId.substring(actualValueLength,1);
        return this.generateDigitoVerification(NitValue) == digitoVerificador;
    }
    /** 
     * @param nit
     * @return digitoVerificador
     * @comment: Does the math logic
     */
    public String generateDigitoVerification(String nit) {        
        Integer[] nums = { 3, 7, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71 };

        Integer sum = 0;

        String str = String.valueOf(nit);
        for (Integer i = str.length() - 1, j=0; i >= 0; i--, j++) {
            sum += Character.digit(str.charAt(i), 10) * nums[j];
        }

        Integer dv = (sum % 11) > 1 ? (11 - (sum % 11)) : (sum % 11);
        return dv.toString();
    }

Could you suggest me a better way to do it please? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:32:36+00:00Added an answer on May 18, 2026 at 8:32 am
    int x = 1343248724;
    int firstpart = x/10;
    int secondpart = x%10;
    
    System.out.println(firstpart);
    System.out.println(secondpart);
    

    Mod (%) gives you the remainder which will be the last digit if you mod 10
    Divide will drop the last digit. That way you don’t have to actually search the string.

    Doing all the length stuff seems a little like overkill to me

    oh and to get your param as a int I would use

    Interger.decode(fiscalId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have First/Last/Previous/Next buttons that change the selected child node of a TreeViewItem. Setting
Scenario: You have an ASP.Net webpage that should display the next image in a
I have the following code: if ($_POST['submit'] == Next) { foreach($_POST['info'] as $key =>
I'm going to start of by noting that I have next to no python
I have heard that closures could be introduced in the next Java standard that
I have the following code, which is the basis for pagination in a larger
I have some code where, if a user has referred X number of people,
i have a input tag which is non editable, but some times i need
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
In my fieldset I have labels next (side) to my textboxes, but for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.