Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am fairly new to Java programming and have been using a for loop in my program. I noticed whenever my program asks for user input, that whenever I press the enter key that is used as the next key for the second iteration of the loop. Is there a way to make this not occur?
Use while loop instead:
while(true){
String input = JOptionPane.showInputDialog(null, "Please enter something.");//take inputs while have not encountered STOP
if(input.equals("STOP")){
System.exit(0);
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm very new to Java and I was wondering why my code wasn't running.
Is there anything I need to do or I have missed out, every time I click run the bar at the bottom is just infinitely saying "running...".
Your code is asking for a user input before logging anything, that's probably why you think it's not running.
Try to print something before like this:
System.out.println("Enter a number:");
int i = scanner.nextInt();
System.out.println("You chose " + i);
(Pseudo code)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Example
if there are 4 slots named A1,B1,C1,D1. If first user enters A1 and when the second user enter the same slot it should error it has already been chosen.
The built-in class java.util.HashMap can do that. Read the docs, perhaps search for some usage examples :)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I intend to let the user choose what they want to filter by choosing 1-5. If the user chooses 1, the program should ask them to enter the year they want to filter, after that, it should check the length of the input, if it is equal to 4 then it should check whether the text file contains a line that matches the input. But if the user enters 2019, which is equal to 4 digit, the record and the no such records will display at the same time.What if i only want the No such record to be disply only the year enter by the user have no record in the text file?
[textfile][1]
This is the part of the code which causes the behavior you do not like:
if(line.contains(input))
{
System.out.println(input);
System.out.println(input);
}
Change it to
if(line.contains(input))
{
System.out.println(line);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Hi I am new to Java and I wanted to learn how to make one program that will create accounts that will be stored in a file in the file of the code and then later you can access it to enter and go to a main program to do something else, I passed all day looking for but everyone using GUI so I do not see the code and it doesn't work well so I wanted to ask to people from here thank you in advance
You can use the Scanner library, which will download text from the console.
Sample part of the program
Scanner download = new Scanner (System.in);
String login = download .nextLine ();
In the login variable, you store the String entered in the input;)
More information :
https://docs.oracle.com/javase/tutorial/essential/io/
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
So I am creating a program that need to create as many strings and integers as the user says. The amount is stored in wordlength, and I need to create these strings programmatically based on the input. Can somebody help me?
First, ask the user to input how many strings to store. This can be done through a Scanner.
Then, make an array of type String with length equal to the user input number.
Then, fill in the array through a Scanner with a for loop.
I hope next time you search about you problem before you write a question about it.