2.31 LAB: Phone number breakdown
Given a long integer representing a 10-digit phone number,output the area code, prefix, and line number using the format(800) 555-1212.
Ex: If the input is:
the output is:
Hint: Use % to get the desired rightmost digits. Ex: Therightmost 2 digits of 572 is gotten by 572 % 100, which is 72.
Hint: Use / to shift right by the desired amount. Ex: Shifting572 right by 2 digits is done by 572 / 100, which yields 5. (Recallinteger division discards the fraction).
For simplicity, assume any part starts with a non-zero digit. So0119998888 is not allowed.
2.31 LAB: Phone number breakdown Given a long integer representing a 10-digit phone number, output the area code, prefix, and line number using the format (800) 555-1212. Ex: If the input is: 8005551212 the output is: (800) 555-1212 Hint: Use % to get the desired rightmost digits. Ex: The rightmost 2 digits of 572 is gotten by 572 % 100, which is 72. Hint: Use / to shift right by the desired amount. Ex: Shifting 572 right by 2 digits is done by 572/100, which yields 5. (Recall integer division discards the fraction). For simplicity, assume any part starts with a non-zero digit. So 0119998888 is not allowed. 417856.2527814.qx3zqy7 LAB ACTIVITY 1 import java.util.Scanner; 2 3 public class LabProgram { 4 5 6 7 8 9 2.31.1: LAB: Phone number breakdown 10 11 12 13} 14 public static void main(String[] args) { Scanner scnr = new Scanner(System.in); long phoneNumber; // Add more variables as needed phoneNumber = scnr.nextLong(); /* Type your code here. */ } Develop mode Submit mode Run program LabProgram.java Enter program input (optional) If your code requires input values, provide them here. Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Input (from above) - LabProgram.java (Your program) 0/10 Load default template... Output (shown below)
2.31 LAB: Phone number breakdown Given a long integer representing a 10-digit phone number, output the area code, prefix
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am