Question
SplitZip: Write an application that prompts the user to enter in a 10 character zip code with a - between the two sections, such as
SplitZip: Write an application that prompts the user to enter in a 10 character zip code with a - between the two sections, such as 49442-1432 Use the split() method to separate the zip code into its two parts and display them separately.
package pack1; import javax.swing.*; public class SplitZip { public static void main(String[] args) { String inputString; String newString; inputString = JOptionPane.showInputDialog(null, "Enter a Zip Code" + " as a series of 10 digits" + " and I will display it in a nice format" + " Enter 999 to quit"); while(!inputString.equals("999")) { newString = inputString.substring(0,6) + '-' + inputString.substring(6,10) ; String[] newerString = newString.split("-"); for(String temp :newerString ) { inputString = JOptionPane.showInputDialog(null, "The number is " + temp + " Enter azip code" + " as a series of 10 digits " + " and I will display it in a nice format" + " Enter 999 to quit"); } } System.exit(0); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started