Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sanple Run: > Java Strings abcdefe gfedcba b) Write a method celled splitNunber

ID: 3735571 • Letter: S

Question

Sanple Run: > Java Strings abcdefe gfedcba b) Write a method celled splitNunber that reads a line from the consists of an international phone number cansole using the Scanner ocject, whach fors x-xxxxoome) The method shouid then spit the number into its three components and then print each of them Sample Run: java Strings Please Enter your phone number in the tollowing format: "country-ares-phone" (e.g. 1-516-7653423): 1-992-6727634 The phone number after split is: Country Code: 1 Area Code: 982 Phone Nurber: 6727634 c) write a method caliled FunFoo that reads a ine L iseved in a variable origina Strinel and a character c, from the user using the Scanner object (hint the Scanner object does then insert the character read from the consale Into the middle of the string creating a string variable cafed newstring. The method should then reverse the (newString) resuting in a string calied reversedString. The methoe should finally print out whether the newString and the reversedString are equat. Note: the method must receive the Scanner object as parameter. Note that you can ute your own method to split the string or you con use the buit-in split method for Strings read dáreetly a character) The methed shoule Sample Run java Strings Enter your String: ababab Enter your character: x The original string is: ababab Spring 2014-13

Explanation / Answer

import java.util.Scanner;

class Main {
public static void splitNumber()
{
// taking user input of a number
Scanner sc = new Scanner(System.in);
System.out.print("Please enter your phone number in the following format: country-area-phone (example: 1-516-7654323): ");
String pnumber = sc.next();
  
// using substring finding out 3 codes
String cc, ac, pn;
cc = pnumber.substring(0,1);
ac = pnumber.substring(2,5);
pn = pnumber.substring(6,pnumber.length());
  
// printing output
System.out.printf("Country code: %s Area Code: %s Phone Number: %s",cc, ac, pn);
}
public static void main(String[] args) {
splitNumber();
}
}

/*SAMPLE OUTPUT
Please enter your phone number in the following format: country-area-phone (example: 1-516-7654323): 1-123-1234123
Country code: 1
Area Code: 123
Phone Number: 1234123
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote