John Powell

Greenhorn
+ Follow
since Nov 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by John Powell

In the following program the user has a simple menu with 3 choices. Two choices (a & b) will run specific methods and the final choice will quit the program. Is there a simple way to ask the user to press a key (once the called method is done) to return to the main menu, rather than returning automatically?

20 years ago
12/25/1975 -> it displays:

12
25
... it hangs on the year. It think it has something to do with the delimiter (/). It doesn't have one at the end of the year so it just hangs. I don't know how you get around the problem. Any ideas?

Thanks
John
20 years ago
Hi,

I'm trying to break apart a string using the Scanner class, then display each string to the console. When I enter in the date 12/15/1975 it just hangs without displaying anything. Any ideas?


20 years ago
Further problems:

I've expanded the original program to read integer values from a file. There are 20 unique values to be stored. In the file there can be multiple instances of each integer (although they will be between 5 and 24). The program should read off all values in the file. Once all values are read it will print off the value of each index and the number of times it appears in the file.

I'm having a hard time figuring out how to record the number of times a value occurs.

20 years ago
I have a simple array that allows the user to enter in integer values, then prints the values of each index of the array. Is it possible to restrict each index to a different integer. In other words if the user enters in the same integer more than once it only gets stored once. Is this possible?

array[0] = 4
array[1] = 6
array[2] = 6 //doesn't get stored because it exists in [0], try again until unique
array[2] = 8
...etc for 20 unique values


20 years ago
Jeff, Michael, thanks for the info.

Michael,

The code you posted works great for most of the invalid characters but it doesn't detect the slashes ("/" and "\"). If I enter either slash for the filename it exits out of the loop even though it's a invalid file name.
20 years ago
I have a loop that requires the user to enter a valid filename to continue. I currently have it set up to loop if the user hits enter without typing anything in (null). In Windows you cannot enter a filename with the forbidden characters \/:*?"<>|. Is there an easy way to check for invalid filenames or do I have to add each individual character to my validation checks (e.g. filename.equals("")||filename.equals("?")||...etc);

20 years ago
I'm trying to read integers from a file (2 integer values separated by whitespace) that the program will use as variables. The following code works correctly. I was wondering, is there an easier method to read integer values from a file and then assign the values to specific variables?

20 years ago
Thank you. It's finally starting to make sense.
20 years ago
Thanks for the info.



The problem I run into now is a Null pointer exception. If I surround the loop with a try/catch it works ok, but it only runs once. I'm not sure if I'm missing something or whether there's a problem with the logic.
20 years ago
I'm trying to ask the user for a file to use. If the file is found then the program continues, but if the file is not found the user is asked to enter the filename again and again until it's found. I assume I could do it with a loop, but I'm unsure of the condition to test for the file not found.

BufferedReader stdin = new BufferedReader(new InputStreamReader
System.in));
String filename = null;

do{
System.out.print("Please enter filename: ");
filename = stdin.readLine();
}while (file is not found???)

Any ideas?
20 years ago