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 6600489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:37:47+00:00 2026-05-25T18:37:47+00:00

I am making this little program using command line arguments, I have like 90%

  • 0

I am making this little program using command line arguments, I have like 90% of the work done. But I am trying to allow the user to enter non numerical values aswell..

User input/output example

Input:

$ java d1 4eb:16 10110110:2 407:8 2048:10

Output:

4eb base 16 is 1259 base 10
10110110 base 2 is 182 base 10
407 base 8 is 263 base 10
2048 base 10 is 2048 base 10

My only problem is with the first input because it has letters and it gives me a number exception error. Any help would be great, and I would prefer a help in the right direction, rather than just the answer. Thank you!

public class homework{
    public static void main (String[] args){
        int answer1=0,check1=0,check2=0,x=0, val=0,rad=0;   //holds integer values user gives and check for : handler, answer etc
        do{   //will continue to loop if no : inputted
        for (x=0;x<args.length;x++){

                check1=args[x].indexOf(":");        //checks input1 for the :
                if(check1==-1){System.out.println("No Colon Found in "+args[x]+".");check1=0;}
                else{
                    String numbers [] = args[x].split(":");     //splits the string at :
                    val = Integer.parseInt(numbers[0]);   //parses [0] to int and assigns to val
                    rad = Integer.parseInt(numbers[1]);     //parses [1] to int and assigns to rad
                    if(val==0||rad==0){System.out.println("The argument "+args[x]+" could not be converted.");check2=0;}
                    else{
                    for (int i = 0; val > Math.pow(rad, i); i++){
                        int digit = (val / (int) Math.pow(10, i)) % 10;
                        int digitValue = (int) (digit * Math.pow(rad, i));
                        answer1 += digitValue;}
                        answer1 = Integer.parseInt(numbers[0], rad);   //finds the answer in base10.
                        System.out.println(val+" base "+rad+" is "+answer1+" base 10.");  //gives user the results
            }}}}while(check1==-1);  }}  //if user forgot : loop
  • 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-25T18:37:47+00:00Added an answer on May 25, 2026 at 6:37 pm

    You need to specify the base when you first call parseInt. For example, if you are parsing a hexidecimal number, you need to specify:

    val = Integer.parseInt(numbers[0], 16)
    

    You receive this exception because you try to parse a hexadecimal number in base 10.

    Maybe you should make the base another command line parameter. I will assume it is the first command line parameter. Then you could run:

    int base = Integer.parseInt(args[0])
    val = Integer.parseInt(number[0], base)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The mechanics of making this work aren't hard, but testing it is a little
I'm making this game where I'm trying to pair people. So I have this
I was making this very simple lex program (just an introductory program). But on
I'm having trouble with the way I designed this little report I'm making. Is
I'm thinking about making a networked game. I'm a little new to this, and
I have tough time making this design decision. I could go with traditional new
Consider a grocery store scenario (I'm making this up) where you have FACT records
I'd like to prevent multiple instances of the same long-running python command-line script from
I want to start making a little window-based program that runs on both Linux
This is a bit esoteric, but there have to be a few people here

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.