I have written a program that does exactly what I want it to do, except one problem. I cannot get the program to loop properly. In its current state, it will ask for an input, process that input and then provide an output, it will then ask the user again for an input but will not return anything. How do I get it to print a new output for a new input? Here is my code:
import java.util.*;
public class cleaner2
{
static Scanner console = new Scanner(System.in).useDelimiter("\\n"); ;
public static void main(String[] args)
{
char letter = ' ';
String letterStr;
String letterOut;
int counter = 0;
int x = 0;
int infiniLoop = 1;
while(infiniLoop == 1)
{
System.out.println("Enter input");
letterStr = console.next();
letterOut = "";
if(letter != '#')
{
while(counter <= 6)
{
letter = letterStr.charAt(x);
if(counter == 3) {letterOut += "-";}
if(letter >= 'a' && letter <= 'z')
letter -= 32;
if (letter >= 'A' && letter <= 'Z')
{
switch (letter) {
case 'A':
case 'B':
case 'C':
letterOut += "2";
break;
case 'D':
case 'E':
case 'F':
letterOut += "3";
break;
case 'G':
case 'H':
case 'I':
letterOut += "4";
break;
case 'J':
case 'K':
case 'L':
letterOut += "5";
break;
case 'M':
case 'N':
case 'O':
letterOut += "6";
break;
case 'P':
case 'Q':
case 'R':
case 'S':
letterOut += "7";
break;
case 'T':
case 'U':
case 'V':
letterOut += "8";
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
letterOut += "9";
}
counter++;
}
x++;
}
System.out.println(letterStr);
System.out.println("The numbers that go with the letters you have entered are " + letterOut);
}
else
System.exit(0);
}
}
}
So if I give an input of " gh% 29 fhso 3^oihfd" it will give me an output of "443-4766
", but if I give it another input it will return nothing. Please help!?! Thanks