I am working on a code that would make talking in a made up language easier, and my problem ends up being right away in my Main class. For a simple test run to see if it would work (and would at least progress to the class instead of getting stuck), I used a simple "language," which is just the words constructed backwards.
import java.util.*; public class languagedecode { public static void main(String [] args) { Scanner in = new Scanner(System.in); System.out.print("Enter coded phrase: "); ArrayList<String>coded = new ArrayList<String>(); while(in.hasNext()) { coded.add(in.next()); System.out.println("1"); } backwards code = new backwards(coded); System.out.println(code.decode()); } }
Pretty basic stuff. When I have the print line in my while loop, it prints out the number of words, as I expect. However, when I move the print line outside of the while loop, it doesn't print any ones. This means that my code never reaches outside of the while loop.
When the print line is in the while loop, here is the output:
Enter coded phrase: i nac llits daer ti tuo duol
1
1
1
1
1
1
1
But when I have the print line on the line after the loop finishes, the output reads as:
Enter coded phrase: i nac llits daer ti tuo duol
In both instances, I am unable to proceed. I am assuming it has something to do with my while loop, but I don't see my problem with it.
e: this is probably a simple solution that I'm missing since I haven't done any keyboard input programs since the first few weeks of my AP Comp Sci course 2 years ago.