It will then prompt to user to enter a word but then the program ends and does nothing, I need the program to loop for as many time the user wants it to.
help? What am I doing wrong?
import java.util.*; //imports util package
import java.io.*;
import javax.swing.*;
public class Phone2 {
public static int Number(char uppercase){ //names variables
int generate;
int num = 0; //determines what the value of each letter is-------------|
if(uppercase=='A' || uppercase=='B' || uppercase=='C'){
num = 2;
}
else if (uppercase=='D' || uppercase=='E' || uppercase=='F'){
num = 3;
}
else if (uppercase=='G' || uppercase=='H' || uppercase=='I'){
num = 4;
}
else if (uppercase=='J' || uppercase=='K' || uppercase=='L'){
num = 5;
}
else if (uppercase=='M' || uppercase=='N' || uppercase=='O'){
num = 6;
}
else if (uppercase=='P' || uppercase=='Q' || uppercase=='R' ||
uppercase== 'S'){
num = 7;
}
else if (uppercase=='T' || uppercase=='U' || uppercase=='V'){
num = 8;
}
else if (uppercase=='W' || uppercase=='X' || uppercase== 'Y' ||
uppercase== 'Z'){
num = 9;
}
else if (uppercase=='-'){
System.out.print("-");
//If the user inputs a "-" a "-" is outputted
}
else if (uppercase==' '){
System.out.print(" ");//enters a space if a space in inputted
}
return num;
}
//--------------------------------------------------------------------------|
public static void main (String[] args) {
String generate;
Scanner input = new Scanner(System.in);
generate = JOptionPane.showInputDialog("How many phone numbers do you want to generate? ");
int GENERATE = Integer.parseInt(generate);
for (int l = 0; l <= GENERATE; l++){
JOptionPane.showInputDialog(
"Enter a string of characters to get its equivalent phone number: ");
//prompts user to enter a word
String phone = input.nextLine();
for (int i = 0; i < phone.length(); i++){
System.out.print(Number(phone.toUpperCase().charAt(i)));
if (i == 6){//begin if
break;
//If the string of characters is over 7 the program will stop at 7
}//end if (i == 7)
//changes all letters to uppercase if needed
}//end for
}// end int l
System.exit(0);
}//end main
}//end program

New Topic/Question
Reply



MultiQuote







|