Question

Outline x 9. Telepho s main case C: System.out.print(2); j++; break; case D: case E: case F: System.out.print(3);

I keep getting this error and I do not know how to fix it. this is the code I've been working on:
please help me
import java.util.*;
public class TelephoneNumber {
public static void main(String[] args)
{String number;
int i=0,j=0;
char c;
Scanner in=new Scanner (System.in);
System.out.println("Enter the phone number: ");
number=in.nextLine();
number=number.toUpperCase();
c=number.charAt(i);
while(c!='\n'&&j<=7)
{switch(c)
{case 'A':
case 'B':
case 'C':
System.out.print("2");
j++;
break;
case 'D':
case 'E':
case 'F':
System.out.print("3");
j++;
break;
case 'G':
case 'H':
case'I':
System.out.print("4");
j++;
break;
case 'J':
case 'K':
case'L':
System.out.print("5");
j++;
break;
case 'M':
case 'N':
case'O':
System.out.print("6");
j++;
break;
case 'P':
case 'R':
case'S':
System.out.print("7");
j++;
break;
case 'T':
case 'U':
case'V':
System.out.print("8");
j++;
break;
case 'W':
case 'X':
case'Y':
System.out.print("9");
j++;
break;
}
if(j==3)
System.out.print("-");
i++;
c=number.charAt(i);
}   

}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

input code:

1 Import java.util. ; 2. public class Telephonel { 3 public static void main(String[] args) 4- { /*declare variables*/ String

while(c!=\n && j<7) 19- /*check the Character and print*/ switch(c) case A: case B: case C: System.out.print(2); j+

case T: case U: case V: System.out.print(8); j++; break; case W: case X: caseY: System.out.print(9); j++; bre

output:

Enter the phone number: omg snap 664-7622 ... Program finished with exit code o Press ENTER to exit console. I

input code:

import java.util.*;
public class Telephone {
public static void main(String[] args)
{
/*declare variables*/
String number;
int i=0,j=0;
char c;
/*take input from user*/
Scanner in=new Scanner (System.in);
System.out.println("Enter the phone number: ");
number=in.nextLine();
/*remove space from String*/
number = number.replaceAll("\\s", "");
number=number.toUpperCase();
c=number.charAt(i);
/*print the telephone number*/
while(c!='\n' && j<7)
{
/*check the Character and print*/
switch(c)
{
case 'A':
case 'B':
case 'C':
System.out.print("2");
j++;
break;
case 'D':
case 'E':
case 'F':
System.out.print("3");
j++;
break;
case 'G':
case 'H':
case 'I':
System.out.print("4");
j++;
break;
case 'J':
case 'K':
case'L':
System.out.print("5");
j++;
break;
case 'M':
case 'N':
case 'O':
System.out.print("6");
j++;
break;
case 'P':
case 'R':
case'S':
System.out.print("7");
j++;
break;
case 'T':
case 'U':
case 'V':
System.out.print("8");
j++;
break;
case 'W':
case 'X':
case'Y':
System.out.print("9");
j++;
break;
default:
break;
}
/*print -*/
if(j==3)
{
System.out.print("-");
}
/*put condition so String array index don't go out the String*/
if(j!=6)
{
i++;
c=number.charAt(i);
}
}


}
}

explain:char s /*take input from user*/ Scanner in=new Scanner (System.in); System.out.println(Enter the phone number: ); number-in

case T: case U: case V: System.out.print(8); j++; break; case W: case X: caseY: System.out.print(9); j++; bre

Add a comment
Know the answer?
Add Answer to:
I keep getting this error and I do not know how to fix it. this is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • I just started working on some code for a password creator. I was doing some testing and I keep g...

    I just started working on some code for a password creator. I was doing some testing and I keep getting this error: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47) at java.base/java.lang.String.charAt(String.java:693) at PasswordCreater.check(PasswordCreater.java:56) at Password.main(Password.java:23 In my code I am having the user create a password that is at least 6 characters long, but no more than 16. Also, include at least one lowercase letter, one uppercase letter, one number digit and one special...

  • Please make the following code modular. Therefore contained in a package with several classes and not...

    Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q {    public static LinkedList<String> dogs = new LinkedList<String> ();    public static LinkedList<String> cats = new LinkedList<String> ();    public static LinkedList<String> animals = new LinkedList<String> ();    public static void enqueueCats(){        System.out.println("Enter name");        Scanner sc=new Scanner(System.in);        String name = sc.next();        cats.addLast(name);        animals.addLast(name);    }   ...

  • Please explain if the following code is actually correct. If the following code correct, please explain...

    Please explain if the following code is actually correct. If the following code correct, please explain why the code works and is also correct. Don’t use * Java’s Integer .toBinaryString(int) in this program./* According to the textbook and the instructor, I am not supposed to use arrays such as int binary[] = new int[25]; I guess this is the reason why this problem is starting to look kind of hard.   Chapter 5 Exercise 37: Java Programming * * (Decimal to...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • I need help debugging this Java program. I am getting this error message: Exception in thread...

    I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...

  • JAVA Can you make this return the first letter of  first and last name capitalized? import java.io.File;...

    JAVA Can you make this return the first letter of  first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 {    public static void main(String[] args) {        //scanner input from user    Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • How would I try/catch recovery from a format mismatch error? The scanner needs to continue prompting...

    How would I try/catch recovery from a format mismatch error? The scanner needs to continue prompting until the user enters a valid number. I know that I would need to try n = kbd.nextInt(); and catch a InputMismatchException and if n<1 or n>100 then I need to print Out of Range Exception. Must be in 1..100. However, I am unsure how to loop all of that. import java.io.*; import java.util.*; public class Lab5 { public static void main( String args[]...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT