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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:22:42+00:00 2026-05-17T08:22:42+00:00

I have this programming assignment that converts between meters and feet, and between kilograms

  • 0

I have this programming assignment that converts between meters and feet, and between kilograms and pounds. When I tell the program I want to convert weight (by entering “w” when prompted), it gives me my the following error:

Error: Too many input characters error.

I worked on this for a long time, but can’t figure it out. Can someone please tell me how to make the weight conversion work like the length conversion?

import java.util.Scanner;

/**
 * This class..
 */
public class UnitConversion3b
{
    public static void main(String[] args)   
    {
        Scanner keyboard = new Scanner(System.in);

        String maxInputWarning = "\nError: Too many input characters."
        + "\nProgram is now terminating.";
        String lengthOrWeight;
        final double LENGTH_CONVERSION_FACTOR = 3.2808399;
        final double WEIGHT_CONVERSION_FACTOR = 2.20462;
        String whichWeightConversion = "empty" , whichLengthConversion = "empty";
        double feet = 0, meters = 0, pounds =0 , kilograms = 0;
        double metersConvertedToFeet, feetConvertedToMeters;
        double poundsConvertedToKilograms, kilogramsConvertedToPounds;

        System.out.println("");
        System.out.print("What kind of value would you like to convert?");
        System.out.print("\nEnter L for length, or W for weight: ");
        lengthOrWeight = keyboard.nextLine();
        if (lengthOrWeight.length() > 1 ) {
            System.out.println(maxInputWarning);
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if ((!(lengthOrWeight.equalsIgnoreCase("l"))
            && (!(lengthOrWeight.equalsIgnoreCase("w"))))){
            System.out.println("\nError: Unrecognized conversion type."
            + "\nProgram is now terminating.");
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if (lengthOrWeight.equalsIgnoreCase("l")){
            System.out.println("\nConverting feet or meters?");
            System.out.print("Enter F to convert feet, or M for meters: "); 
            whichLengthConversion = keyboard.nextLine();
        }

        if (whichLengthConversion.length() > 1 ) {
            System.out.println(maxInputWarning);
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if ((!(whichLengthConversion.equalsIgnoreCase("f"))
            && (!(whichLengthConversion.equalsIgnoreCase("m"))))){
            System.out.println("\nError: Unrecognized unit of "
            + "measurement.\nProgram is now terminating."     );
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if (whichLengthConversion.equalsIgnoreCase("f")){
            System.out.print ("Enter the number of feet to"
            + " convert to meters: ");
            feet = keyboard.nextDouble();
            feetConvertedToMeters = feet / LENGTH_CONVERSION_FACTOR;
            System.out.println("The number of meters in " + feet +
            " feet is " + feetConvertedToMeters + ".");
            keyboard.nextLine();
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if (whichLengthConversion.equalsIgnoreCase("m")){
            System.out.print ("Enter the number of meters to"
            + " convert to feet: ");
            meters = keyboard.nextDouble();
            metersConvertedToFeet = meters * LENGTH_CONVERSION_FACTOR;
            System.out.println("The number of feet in " + meters +
            " meters is " + metersConvertedToFeet + ".");
            keyboard.nextLine();
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        }

        if (lengthOrWeight.equalsIgnoreCase("w")){
            System.out.println("Converting pounds or kilograms?");
            System.out.print("Enter P to convert pounds, or K for kilograms: ");
            whichWeightConversion = keyboard.nextLine();
        }

        if (whichWeightConversion.length() > 1 ) { 
            System.out.println(maxInputWarning);
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if ((!(whichWeightConversion.equalsIgnoreCase("p"))
            && (!(whichWeightConversion.equalsIgnoreCase("k"))))){
            System.out.println("\nError: Unrecognized unit of "
            + "measurement.\nProgram is now terminating."     );
            System.out.print("Press Enter to continue ... ");
            return;
        } else if (whichWeightConversion.equalsIgnoreCase("p")){
            System.out.println("Enter the number of pounds to"
            + " convert to kilograms:");
            pounds = keyboard.nextDouble();
            poundsConvertedToKilograms = pounds / WEIGHT_CONVERSION_FACTOR;
            System.out.println("The number of pounds in " + kilograms +
            " kilograms is " + poundsConvertedToKilograms + ".");
            keyboard.nextLine();
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;
        } else if (whichLengthConversion.equalsIgnoreCase("k")){
            System.out.print ("Enter the number of kilograms to"
            + " convert to pounds: ");
            kilograms = keyboard.nextDouble();
            kilogramsConvertedToPounds = kilograms * WEIGHT_CONVERSION_FACTOR;
            System.out.println("The number of pounds in " + pounds +
            "pounds is " + kilogramsConvertedToPounds + ".");
            keyboard.nextLine();
            System.out.print("Press Enter to continue ... ");
            keyboard.nextLine();
            return;

        } else{ 
            return;
        }
    }
}
  • 1 1 Answer
  • 1 View
  • 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-17T08:22:43+00:00Added an answer on May 17, 2026 at 8:22 am

    You made lots of errors by not changing the code while copy pasting the logic from one place to the other. Your code can be improved a lot by reducing the repetitions and I will be more optimistic in my ‘if’ ‘else’ conditions to capture the right cases first and leaving all the wrong cases to the end…Below is the working version of your code modified slightly by fixing the typos and order of the logic.

    import java.util.Scanner;
    
    public class UnitConversion3b {
        public static void main(String[] args) {
    
            Scanner keyboard = new Scanner(System.in);
    
            String maxInputWarning = "\nError: Too many input characters."
                    + "\nProgram is now terminating.";
            String lengthOrWeight;
            final double LENGTH_CONVERSION_FACTOR = 3.2808399;
            final double WEIGHT_CONVERSION_FACTOR = 2.20462;
            String whichWeightConversion = "empty", whichLengthConversion = "empty";
            double feet = 0, meters = 0, pounds = 0, kilograms = 0;
            double metersConvertedToFeet, feetConvertedToMeters;
            double poundsConvertedToKilograms, kilogramsConvertedToPounds;
    
            System.out.println("");
            System.out.print("What kind of value would you like to convert?");
            System.out.print("\nEnter L for length, or W for weight: ");
    
            lengthOrWeight = keyboard.nextLine();
            if (lengthOrWeight.length() > 1) {
                System.out.println(maxInputWarning);
                System.out.print("Press Enter to continue ... ");
                keyboard.nextLine();
                return;
            } else if ((!(lengthOrWeight.equalsIgnoreCase("l")) && (!(lengthOrWeight
                    .equalsIgnoreCase("w"))))) {
                System.out.println("\nError: Unrecognized conversion type."
                        + "\nProgram is now terminating.");
                System.out.print("Press Enter to continue ... ");
                keyboard.nextLine();
                return;
            } else if (lengthOrWeight.equalsIgnoreCase("l")) {
                System.out.println("\nConverting feet or meters?");
                System.out.print("Enter F to convert feet, or M for meters: ");
                whichLengthConversion = keyboard.nextLine();
    
                if (whichLengthConversion.length() > 1) {
                    System.out.println(maxInputWarning);
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
                } else if ((!(whichLengthConversion.equalsIgnoreCase("f")) && (!(whichLengthConversion
                        .equalsIgnoreCase("m"))))) {
                    System.out.println("\nError: Unrecognized unit of "
                            + "measurement.\nProgram is now terminating.");
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
                } else if (whichLengthConversion.equalsIgnoreCase("f")) {
                    System.out.print("Enter the number of feet to"
                            + " convert to meters: ");
                    feet = keyboard.nextDouble();
                    feetConvertedToMeters = feet / LENGTH_CONVERSION_FACTOR;
                    System.out.println(feet + " Feet in Meters is "
                            + feetConvertedToMeters + ".");
                    keyboard.nextLine();
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
                } else if (whichLengthConversion.equalsIgnoreCase("m")) {
                    System.out.print("Enter the number of meters to"
                            + " convert to feet: ");
                    meters = keyboard.nextDouble();
                    metersConvertedToFeet = meters * LENGTH_CONVERSION_FACTOR;
                    System.out.println(meters + " Meters in Feet is "
                            + metersConvertedToFeet + ".");
                    keyboard.nextLine();
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
                }
            }
    
            else {
                System.out.println("Converting pounds or kilograms?");
                System.out.print("Enter P to convert pounds, or K for kilograms: ");
                whichWeightConversion = keyboard.nextLine();
    
                if (whichWeightConversion.length() > 1) {
                    System.out.println(maxInputWarning);
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
                } else if ((!(whichWeightConversion.equalsIgnoreCase("p")) && (!(whichWeightConversion
                        .equalsIgnoreCase("k"))))) {
                    System.out.println("\nError: Unrecognized unit of "
                            + "measurement.\nProgram is now terminating.");
                    System.out.print("Press Enter to continue ... ");
                    return;
                } else if (whichWeightConversion.equalsIgnoreCase("p")) {
                    System.out.println("Enter the number of pounds to"
                            + " convert to kilograms:");
                    pounds = keyboard.nextDouble();
                    poundsConvertedToKilograms = pounds / WEIGHT_CONVERSION_FACTOR;
                    System.out.println(pounds + " Pounds in Kilograms is "
                            + poundsConvertedToKilograms + ".");
                    keyboard.nextLine();
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
                } else if (whichWeightConversion.equalsIgnoreCase("k")) {
                    System.out.print("Enter the number of kilograms to"
                            + " convert to pounds: ");
                    kilograms = keyboard.nextDouble();
                    kilogramsConvertedToPounds = kilograms
                            * WEIGHT_CONVERSION_FACTOR;
                    System.out.println(kilograms + " Kilograms in Pounds is "
                            + kilogramsConvertedToPounds + ".");
                    keyboard.nextLine();
                    System.out.print("Press Enter to continue ... ");
                    keyboard.nextLine();
                    return;
    
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this programming problem, I'm using C#. I want to check if varA
I have this problem since I'm beginning in OOP programming I want to close
I have a programming assignment and we are asked to create a program in
I have an assignment in my C programming class to write a program to
Say I have this: private list<myClass> myCollection; Is there a programming idiom to shorten
Totally new to programming so kindly excuse the silly question. I have this URL
Ever since I started programming this has been something I have been curious about.
I have just read this in the book OpenCV 2 Computer Vision Application Programming
This not a programming question but Most of the programmers using Eclipse should have
I know this is not programming related, but I have a scenario. Each video

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.