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

  • SEARCH
  • Home
  • 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 8887583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:50:42+00:00 2026-06-14T21:50:42+00:00

I’m trying to build a calculator without any operators that relate to the opration

  • 0

I’m trying to build a calculator without any operators that relate to the opration itself I try to solve (comparison operators and loops with operators are fine).
problem is, Eclipse is showing this in the console:

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Calculator.addOne(Calculator.java:22)
at Calculator.add(Calculator.java:78)
at Program.main(Program.java:8)

And this is my code – Calculator class: http://pastebin.com/jLGe6atB

And my main() method:

public class Program {
public static void main(String[] args) {
    Calculator calculator1 = new Calculator(8135, 6);
    calculator1.add();
}
}

Can someone tell me what is the problem? (Please don’t ask why am I doing this, it’s just for fun)

Thanks and sorry for your time.

REQUEST: “post add() and addOne() here please:

        public int addOne(int DigitArray)
    {
            String stringNum1 = Integer.toString(DigitArray);
            String[] arrNum1 = stringNum1.split("");
            int[] newArrNum1 = new int[arrNum1.length];
               for (int i = 0; i < arrNum1.length; i++) {
                  newArrNum1[i] = Integer.parseInt(arrNum1[i]);
               }
            int lastDigit = newArrNum1[newArrNum1.length-1];
            switch(lastDigit)
            {
            case 0:
                    lastDigit = 1;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 1:
                    lastDigit = 2;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 2:
                    lastDigit = 3;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 3:
                    lastDigit = 4;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 4:
                    lastDigit = 5;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 5:
                    lastDigit = 6;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 6:
                    lastDigit = 7;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 7:
                    lastDigit = 8;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 8:
                    lastDigit = 9;
                    System.out.println(lastDigit);
                    return lastDigit;
            case 9:
                    lastDigit = 0;
                    updateNumberPlus(lastDigit, arrNum1, newArrNum1);
                    System.out.println(lastDigit);
                    return lastDigit;
            default:
                    return lastDigit;
            }
    }
    public int add()
    {
            int i = 0;
            while(i <= num2)
            {
                    i++;
                    this.addOne(num1);
                    if(i == num2)
                    {
                            result = 0;
                            System.out.print(result);
                            return result;
                    }
            }
            return result;
    }
  • 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-06-14T21:50:43+00:00Added an answer on June 14, 2026 at 9:50 pm

    When you do a String.split("") you will get an empty String element as the first and last elements of your Array.

    You then iterate over the array, calling Integer.parseInt() on each element, which fails on the empty string elements.

    A simple hack would be to change your for loop to look like;

    for(int i = 1; i < arrNum1.length - 1; i++) {
    

    It’s a little ugly though 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:

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.