Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
11 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 ...
Anugraha Mahesh's user avatar
-1 votes
0 answers
37 views

Why is this throwing a NoSuchElementException? [duplicate]

This is part of a slightly bigger program. It takes input from a user and assigns that to values in an object. It doesn't make it past the first input before throwing an error. I've tried researching ...
Scott Burkhart's user avatar
0 votes
1 answer
70 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 ...
Smetana Po Aktsii's user avatar
0 votes
0 answers
45 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 ...
Szihuma's user avatar
0 votes
0 answers
38 views

How take input while "message"/r in a loop

Hello I am not really sure how to word the title, But I am trying to build a blockchain for my first big project and I have 3 threads, a node/miner/wallet. When mining it is constantly printing out ...
Denis Dovzhanyn's user avatar
0 votes
1 answer
50 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 ...
Sơn Trần's user avatar
0 votes
0 answers
20 views

Scanner doesn't take input after first round of the for loop [duplicate]

I want to run a block of code which repeats until user wants to exit themself. So I put it into a for loop where it'll keep iterating until user enters 0 as a choice. It works fine in the first ...
Abhay Sahu's user avatar
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 ...
vin's user avatar
  • 11
-1 votes
1 answer
116 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 ...
Bill Da Scerno's user avatar
0 votes
0 answers
27 views

can anyone explain why the string input taken after integer input in java gives error [duplicate]

Why does attempting to take a string input after an integer input using Scanner in Java often result in unexpected behavior or errors? What are the underlying details of this problem?" I ...
SIDDHANT SINGH's user avatar
0 votes
0 answers
33 views

I encountered a strange problem while using Scanner in java. Its displays the phrase twice [duplicate]

Code import java.util.Scanner; public class sortirovka { public static void main(String[] args){ int[] massiv = new int[10]; Scanner cons = new Scanner(System.in); for(int ...
vnightly's user avatar
0 votes
1 answer
70 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[] ...
Mohammad Naser's user avatar
-1 votes
1 answer
139 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 (...
Reffert's user avatar
0 votes
0 answers
20 views

how take two string input from user [duplicate]

import java.util.Scanner; public class userInput { public static void main(String[] args) { // TODO Auto-generated method stub Scanner obj = new Scanner(System.in); ...
lokhande_rutu's user avatar
1 vote
2 answers
119 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 ...
Арсений Коротков's user avatar
-1 votes
1 answer
109 views

Why isn't "\n" interpreted as newline character when a String like, "abc\nabc" is given as input via Scanner class in Java?

In Java, when we try to print a Hardcoded String like, "abc\nabc", we observe a line change after the first abc but when we take same input via sc.next() or sc.nextLine() it prints out '\n' ...
Digvijay Singh's user avatar
0 votes
0 answers
38 views

Inputs from console do not become String in program through nextLine

I am making a program that first asks the user to input a number from the console to choose which umber type they'd like to convert to the other two, after which the user enters a number in the form ...
Aidan Devine's user avatar
0 votes
1 answer
300 views

SIGHUP error handling, exception throws in Scanner class how can I fix this problem?

import java.util.*; class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); String name=sc.next(); System.out.println("No ...
Swati's user avatar
  • 1
-1 votes
1 answer
55 views

Using System.in to process piped in data AND to await user input

I have a program in java that I would like to be able to attend to piped in data (as in, '(echo "dor = 4"; echo "dor * 2") | program'. That said, it seems System.in only works as ...
Clovergheister's user avatar
0 votes
1 answer
63 views

Scanner.next() doesn't read the first character in every second line

The following inputs are supplied to this piece of code: 5 0 4 15 1 0 14 2 7 3 23 2 0 7 3 1 23 4 16 4 2 15 3 9 The problem is that whenever the line number is odd, the first integer will not be read ...
Goamhobala's user avatar
-1 votes
1 answer
244 views

Assigning Hex Values from String to an Integer variable

Context: Java 22 I'm trying to read data from a table that includes both Hex and Dec values in a CSV. These values would look something like this: 0x00000000,0 0x03000000,1 0x05000000,2 What I'm ...
Spenser Spratlin's user avatar
0 votes
2 answers
73 views

how to sort input from java scanner? [closed]

I am working on a simple project in Java which need to take in a string through a Scanner object and then sort out the inputs which can be integers. These then need to be fed in pairs to run the ...
Steven Meesters's user avatar
1 vote
2 answers
55 views

How can the scanner reread the entire file after it has already executed hasNextLine once?

What is the optimal way for the scanner to reread the contents of the file from the beginning? Since in the verticesSet function, I'm using while (scanner.hasNextLine()), which reads until there are ...
user23819755's user avatar
-2 votes
1 answer
95 views

Why does the scanner still run even though expression equates to false [duplicate]

I've come across an issue with my scanner functionality. Even after entering "exit" in the terminal, the scanner keeps running. My suspicion is that this behavior is linked to the ...
dracule22's user avatar
0 votes
0 answers
49 views

NoSuchElementException at java.util.Scanner.nextLine

My program encountered a runtime exception while attempting to read a file using a Scanner. Exception in thread "main" java.util.NoSuchElementException: No line found at java.util....
sachin samuel's user avatar
0 votes
0 answers
22 views

Issues with sc.next and sc.nextLine in java: sc.next means i cannot have multi-worded inputs; sc.nextLine consumes the first input in a for loop [duplicate]

The issue is, when i use sc.nextLine in the code (in the line I marked) the for loop consumes the first input and then accepts the others. Using sc.next instead fixes this issues but I cannot accept a ...
Elliot Hannelly's user avatar
-1 votes
1 answer
62 views

My program recurses. Is there a way to fix this?

My problem is that whenever I try to catch the exception on "scannerGettingStarted", I always get the try catch exception from runProgram. I know that there is a recursion that is happening, ...
CarlKilla's user avatar
1 vote
1 answer
67 views

How to make it so my program doesn't ask for input twice?

I'm using the Scanner class in Java and I ran into an issue where my program would do something like this: public static void answer() { System.out.print("\t> "); command = scan....
RystaMakesGames's user avatar
0 votes
0 answers
25 views

How to reiterate while loop containing scanner in order to restart code in java? [duplicate]

Basically the issue is that once the main method completes, it prompts to restart the code or not, except it terminates after prompting, no matter what I enter. How do I fix this? import java.awt....
Luka's user avatar
  • 1
0 votes
1 answer
18 views

How to do this for loop properly?

How do I do this properly for loop properly? Ask the user for their name. Ask the user for the number of times to print their name and save this to an int variable called n. Create a for loop that ...
Ken's user avatar
  • 21
0 votes
0 answers
17 views

scan.nextLine() does not work after scan.nextDouble() in java [duplicate]

I want to take 3 inputs of an integer, double and string, so i wrote the following 3 lines: Scanner scan = new Scanner(System.in); int i = scan.nextInt(); double d = scan.nextDouble(); ...
ggj_07's user avatar
  • 1
0 votes
0 answers
39 views

Passing a scanner as a perameter to a Java Method

I'm fairly new to programming and newer still to Java. I'm trying to write some code that will take input from a user and create a new object (instance?) from it. The concept is adding and updating a ...
shandy068's user avatar
1 vote
0 answers
26 views

Why is Scanner.nextLine not running the second and third times? [duplicate]

I have a program that is supposed to give a user three chances to get a password before it locks them out, but the code is only correctly getting the password on the first attempt. import java.util....
Robocittykat's user avatar
0 votes
0 answers
30 views

Console app runs diffrently than in netbeans

I made a small card based game in Netbeans. I went to build and test it in the console and it prints eveything twice before the user get to input there move. It does not do it in Netbeans. I am using ...
Papers2's user avatar
4 votes
1 answer
90 views

It gives error since I closed the scanner in main method but I created a new scanner in the method [duplicate]

i tried to creating a new scanner after i closed the former in the main. but it gives error. i thought that i created a new scanner in the method than i closed it so it would read the new inputs ...
Fatih çağlar's user avatar
0 votes
2 answers
113 views

use of hasNext() and hasNextInt()

As the hasNext() returns True when there is a token in buffer otherwise false And hasNextInt() return true if the token in buffer can be interpreted as int otherwise false. If in case, the buffer is ...
Nitin's user avatar
  • 1
0 votes
2 answers
89 views

File not found when trying to pass user given file to new scanner object

public void readItemData() { try { Frame frame = null; FileDialog fileBox = new FileDialog(frame ,"Open", FileDialog.LOAD); fileBox.setVisible(...
Massiveegg9's user avatar
0 votes
0 answers
130 views

Why do I get a java.util.NoSuchElementException

I am practicing some algorithm problems. While I use Scanner to get some input, my program throws a java.util.NoSuchElementException in thread "main", and I really don't know why. It can ...
neverdieFire's user avatar
0 votes
2 answers
113 views

How to get a String and an int vs. just a String with Scanner?

I have some code that runs an addition or subtraction of two numbers based on a user's input, wherein they can either type a String followed by an integer to perform an operation, OR just a String to ...
Babbit's user avatar
  • 3
-2 votes
1 answer
109 views

Can we skip EOF when reading input? [closed]

After I catch eof, if I try to read information from input again, I no longer get new information. Is there any way I can resume reading the data? Scanner s = new Scanner(System.in); while (s....
skver's user avatar
  • 1
0 votes
0 answers
23 views

Correct reading from console in the same line with request [duplicate]

I'm trying to write request, which user can see in console and in the same line he can give response, but I have some issues with that. import java.util.Scanner; public class Main { final static ...
Ruzvelt's user avatar
  • 25
-1 votes
1 answer
69 views

Use a scanner alongside a Throttle class

I have a project where we have a used a Throttle class and MainClass. We have to now create a new while loop that prompts the user for the position data, using a scanner, from 0 to 6. When the user ...
darth.vater's user avatar
0 votes
0 answers
20 views

Why is an empty string assigned to a variable "text" first and only then is the entered value assigned? [duplicate]

I see that using the "hasNextInt()" method assigns an empty string to a variable "text" first and only then the entered value. Why is that? Input: 15 enter Output: 15 false 15 ...
Alexey's user avatar
  • 1
0 votes
0 answers
32 views

Why does this simple java array program skip the first input? [duplicate]

When I try to run this simple java program that asks how many words you would like the array to contain and asks you to enter a word at each index in the array, it skips the first input and prints &...
kpunta's user avatar
  • 1
0 votes
0 answers
42 views

NoSuchElementException when using Java.Util.Scanner in console app

I am new to Java and I am doing hospital software in console app. I got a class to select options. The exception is thrown only when option 2 is selected. I don't want the code to stop, but continuing ...
Todor's user avatar
  • 1
4 votes
2 answers
93 views

Can I skip a delimiter without repeating it in Kotlin/java.util.Scanner?

Consider a string like "1: 2, 3, 4" ^^ ^^^^^^^ id items I can parse this using val sc = Scanner("1: 2, 3, 4") val id = sc.useDelimiter(": ").nextInt() val items = sc....
Felix Dombek's user avatar
  • 14.3k
0 votes
1 answer
63 views

Java while loop not breaking when using HasNextLine()

I know that there's similar questions, but my while loop times out when using HasNextLine() and none of the solutions online have fixed it so far. public static main(String [] args) { Scanner s = ...
David Pascual's user avatar
-1 votes
1 answer
61 views

Problems when using Mockito and JUnit for testing in Java Project

I have some problems when testing with mockito and JUnit, I want to test a method that take data from user input. When I use String id = "E833462", the test function work correctly, but when ...
twentyfourk's user avatar
0 votes
0 answers
37 views

Why does hasNext() wait for input? [duplicate]

In this simple code, I'm checking if a Scanner has something in the input buffer or not. So I used hasNext() to check whether it has something or not. But instead of returning "false" (in ...
Rachid's user avatar
  • 31
-1 votes
2 answers
77 views

Scanning the next line, but only to a certain length

I have an existing code, where I have to scan the next sentence that the user types into the console. This sentence can be no longer than 99 characters. My current code takes the .nextLine() method, ...
Thinchance's user avatar

1
2 3 4 5
130