6,471 questions
2
votes
1
answer
156
views
How do I call Scanner with Swing in Java?
I am trying to start a console based Main.main() from a Swing GUI, but the Scanner doesn't accept any input, I think that scanner isnt running.
This is my code in the GUI:
bankBtn.addActionListener(e -...
2
votes
2
answers
95
views
Java - Deleting previous console inputs out of System.in - Why does 1 version of my Code work and not the other version?
The diffrence in the code is in the deleteInput()-Method. Everything else is the same.
The question is at the end, because it's about the console output.
The code:
public class DeletePreviousInputs {
...
0
votes
1
answer
54
views
how to keep the value up and organize the cycle correctly?
I have this code:
import java.util.List; import java.util.Scanner;
public class AddElementsInLists {
private static final Object lock1 = new Object();
private static final Object lock2 = new ...
0
votes
1
answer
59
views
How to enter double and string alternately in an infinite loop? [duplicate]
I'm trying to write a calculator In Java, but I don't understand how to provide infinite input of double and string in turn. It keeps throwing InputMismatchException, I don't know what to do.
public ...
-1
votes
1
answer
57
views
NoSuchElementException and premature closure of scanner
I have made a program that reads 5 integers and outputs its polarity(positive or negative), its type(odd or even). Used Scanner.nextLine() to read the input as string and split it with .split("\s+...
1
vote
1
answer
71
views
Why is my console not immediately printing the previous line when using a java scanner?
I have the following simple Java program, which asks for a username (via the Scanner) and a password (via the Console). Note I am NOT running this in an IDE such as eclipse, so that bug does not apply ...
0
votes
0
answers
31
views
JUnit test cases skipped for a specific class despite proper setup in Gradle and Java version
I am working on an end-to-end testing class for my Java project using JUnit 5. However, only the test cases in a specific test class are being skipped, even though other test cases in the project run ...
0
votes
1
answer
74
views
Scanner.readLine() with custom line delimeter
I have a string that needs to be read using the Scanner class from the beginning to the \n character. The problem is that the source stream in my case may contain the character \u2028. I know that the ...
0
votes
0
answers
46
views
Scanner skipping .hasNextDouble() [duplicate]
I am trying to read several doubles from a file and save them in an array. The first number in the file is an integer, which should then determine the size of the array. This works. but when I try to ...
-1
votes
1
answer
62
views
How to get Java console scan 2 strings separated by TAB key
I cannot type the TAB key into the console for 2 strings separated by the tab key, i used the split method but it didn't work. The Java console does not accept the TAB key.
Here's a snippet of my code
...
0
votes
0
answers
29
views
Why are my output values displaying E when they shouldn't be that long? [duplicate]
When running a program for calculating investor loans, my program provides an output of owner future value that is extremely long and contains an "E". I'm not sure if my formulas are wrong ...
0
votes
1
answer
136
views
Java Scanner throws IndexOutOfBoundsException if an asynchronous thread is interruped while waiting on nextLine() and another nextLine() is called
What title says.
Java Scanner throws IndexOutOfBoundsException if an asynchronous thread is interrupted while waiting on nextLine() and another nextLine() is called.
Here is some code that reproduces ...
0
votes
1
answer
82
views
how to use ? and : expression in java
I want to use ? : expression instead of if with 4 conditions in this code but i dont know how< any answers please?
import java.util.Scanner;
public class Ex13 {
public static void main(String[] ...
-1
votes
1
answer
235
views
How to populate an array automatic with an user` input?
i m writing a code as homework, the task is to create a code, where the user give a number (for example 4 ) and the output will be all the number from 4 ( the users input ) till the length of array (...
1
vote
2
answers
140
views
Running a console application (CLI) from docker-compose
Have java code:
public class Hello {
public static void main(String[] args) {
System.out.println("Enter Name");
Scanner reader = new Scanner(System.in);
String s ...