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
  • Could you help me pleas , this is my code I want change it to insert...

    Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...

  • 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...

  • I am working on this switch statement code and I am getting errors. Please help. import...

    I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) {    int choice;    Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result;       Scanner scanner = new Scanner(System.in);    System.out.print("Enter 1\t UsDollars to Yen:...

  • (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...

  • For this code after case 0, I need it to ask the user if they would...

    For this code after case 0, I need it to ask the user if they would like to see the menu again and some type of if statement or loop to ask them yes or no and if yes print again and if no end program. So it would ask if they would like to see the menu again then ask what their choice is. If yes print menu and if no end program. import java.util.InputMismatchException; import java.util.*; import java.io.*;...

  • 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...

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