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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:04:23+00:00 2026-06-11T12:04:23+00:00

The code below throws this error, and I’m not sure why. There is clearly

  • 0

The code below throws this error, and I’m not sure why. There is clearly a problem with outputting String.format to the str variable, but I don’t know what’s wrong with it.

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'i'
    at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.lang.String.format(Unknown Source)
    at Donor.toString(Donor.java:41)
    at Donor.main(Donor.java:65)

–

import java.util.Scanner;

public class Donor {

    public String name;
    public int age;
    public double donation;

    Donor() {

        //Initialized to these values for debugging
        name = "NoName";
        age = 0;
        donation = 0;

    }

    Donor(String nameinit, int ageinit, double donationinit) {

        name = nameinit;
        age = ageinit;
        donation = donationinit;

    }

    public String toString() {

        String str = "";

        str = String.format("%s-30%i-6$%d-20", name, age, donation);

        return str;

    }

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        String nameinit = null;
        int ageinit = -1;
        double donationinit = -1;
        String outp = null;

        System.out.print("Enter the donor's name: ");
        nameinit = input.nextLine();

        System.out.print("Enter the donor's age: ");
        ageinit = input.nextInt();

        System.out.print("Enter the donation amount: ");
        donationinit = input.nextDouble();

        Donor d = new Donor(nameinit, ageinit, donationinit);
        outp = d.toString();

        System.out.printf("%s30 %s6 %s10", "Name", "Age", "Donation");
        System.out.print("\n" + outp);

        input.close();

    }

}
  • 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-11T12:04:24+00:00Added an answer on June 11, 2026 at 12:04 pm

    Use d for int instead of i and ffor double instead of d in the following line

    str = String.format("%s-30%i-6$%d-20", name, age, donation); 
    

    You can read about formatting syntax here http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html.

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

Sidebar

Related Questions

Any time I use the code below it throws the error: Method 'System.String Join(System.String,
Hi I have below pseudo code with throws an exception like this throw new
I have presented the code below. The compiler throws error when I overload an
This code below allows me to find the word error in all my files
See the code below. Why does accessing [self.objects count] throw this error, when the
I have written code for threading in Python. It throws the error below. How
When I run the code below, why does it throw this error? Exception in
Look please below this codes throw me : FormatException was unhandled by user code
e.g. The code below throws a ClassCastException when the second Object is added to
The below code in Java throws Null pointer exception. public class New{ int i;

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.