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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:30:51+00:00 2026-05-20T08:30:51+00:00

I dont get why when i compile this code i get the incorrect zip

  • 0

I dont get why when i compile this code i get the incorrect zip code.

John Smith
486 test St.
Yahoo, MA 898 - 2597JohnSmith
486 test St.
Yahoo, MA 898  2597

Code

public class test
{
  public static void main(String[] args) {

      String firstName = "John";
      String lastName = "Smith";
      int streetNumber = 486;
      String streetName = "test St.";
      String city = "Yahoo";
      String state = "MA";
      int zip =  01602;
      int zipplus4 = 2597;


     System.out.print(firstName + " " + lastName + "\n" + streetNumber + " " + streetName + "\n" + city + ", " + state + " " + zip + " - " + zipplus4);

     System.out.println(firstName + lastName);
     System.out.println(streetNumber + " " + streetName);  
     System.out.println(city + ", " + state + " " + zip + " - " + zipplus4);  

    }

    }
  • 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-20T08:30:52+00:00Added an answer on May 20, 2026 at 8:30 am

    When you specify a number with a leading zero, it gets treated as an Octal (base-8, as opposed to decimal base-10 or hexadecimal base-16).

    01602 octal == 898 decimal
    

    Since Java wasn’t desgined with Zip codes in mind, to get the desired effect, drop the leading zero, and format it when you print it:

    System.out.println(city + ", " + state + " " + new java.text.NumberFormat("00000").format(zip) + " - " + new java.text.NumberFormat("0000").format(zipplus4));  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why don't we get compile errors on inline code errors in asp.net mvc views
i tried to compile by iphone app in xcode and i got this Code
This is the error I'm getting when trying to compile some code that uses
I cant get my code to compile. I added in a iterator design pattern
I thought this was pretty straight forward but I don't get the same results
I have to be missing something obvious here. I don't get why this cast
I don't get any errors when I compile my game. The only problem is
I have this code: string get_md5sum(unsigned char* md) { char buf[MD5_DIGEST_LENGTH + MD5_DIGEST_LENGTH]; char
The following code is producing a warning when I compile it on 32-bit systems:
I'm learning to use Java's Pattern and Matcher, and this is an example code

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.