java.util.scanner

Exception in thread “main” java.util.NoSuchElementException: No line found 3 [duplicate]

妖精的绣舞 提交于 2019-12-10 12:24:22
问题 This question already has an answer here : How to use java.util.Scanner to correctly read user input from System.in and act on it? (1 answer) Closed last year . In this code, throws me this exception: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1540) at com.cristianvalero.filetransfers.main.client.Client.askToDo(Client.java:98) at com.cristianvalero.filetransfers.main.client.Client.run(Client.java:64) at com

How to combine the GUI class and the scanner class?

青春壹個敷衍的年華 提交于 2019-12-10 12:05:18
问题 I'm new in java and well I'm trying to create a program that will first ask the user to for some number and will output a volume, area and so on. Also I want to display a rectangle I don't know how that can be done because my program runs fine it just won't display the rectangle. What can I do? package testchap3; import java.util.*; import javax.swing.JApplet; import java.awt.*; public class Chapter_3 extends JApplet { public void paint(Graphics page) { page.drawRect(50,50,60,60); } public

Java - Scanner execute only the Int and “skip” the Strings data types when i input String data before the Int ones [duplicate]

情到浓时终转凉″ 提交于 2019-12-10 11:59:40
问题 This question already has answers here : Scanner is skipping nextLine() after using next() or nextFoo()? (16 answers) Closed 4 years ago . While I'm working with java.util.Scanner , I tried to use integers and String s at data input. The problem that I faced is, when I input an Int data before a String one, the console skip the String data and go immediately to the next Int one. Here is my simple problem where the problem is happening : package justForTest; import java.util.Scanner; public

java.util.Scanner read remaining content

限于喜欢 提交于 2019-12-10 11:27:01
问题 Using a java.util.Scanner instance, is it possible for it to return all remaining content? My scenario is that once I have read a number of fields within a String , I just want to get whatever is left and store that somewhere else. For example my content could include: 1,2,Some Garbage with \' special characters and so on I would construct the scanner using , as the delimiter, call getInt() twice and then want to get "Some Garbage with \' special characters and so on" back in one call. 回答1:

BigDecimal Method returns vague results, why does this happen?

ぐ巨炮叔叔 提交于 2019-12-10 10:54:19
问题 Code: package tk.vivekpatani.www; import java.math.BigDecimal; import java.util.Scanner; public class SimpleCalc { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); try{ System.out.println("Welcome to the Calculator!"); System.out.println("Enter Number 1:"); double num1 = sc.nextDouble(); System.out.println("Enter Number 2:"); double num2 = sc.nextDouble(); BigDecimal bd1 = new BigDecimal(num1); BigDecimal bd2 = new BigDecimal

Problem using the nextLine() and hasNextLine() methods of Scanner

不想你离开。 提交于 2019-12-10 04:12:10
问题 I have a log file containing the following data: Shortest path(2)::RV3280-RV0973C-RV2888C Shortest path(1)::RV3280-RV2502C Shortest path(2)::RV3280-RV2501C-RV1263 Shortest path(2)::RV2363-Rv3285-RV3280 From each line, i require the number within the brackets, name of the first protein (RV3280 in the first line) and the name of the last protein (RV2888C in the first line). I have written a code for this using the Scanner object. try{ Scanner s = new Scanner(new File(args[0])); while (s

Java.util.scanner error handling

谁说胖子不能爱 提交于 2019-12-09 17:56:40
问题 I'm helping a friend with a java problem. However, we've hit a snag. We're using Java.Util.Scanner.nextInt() to get a number from the user, asking continiously if the user gives anything else. Only problem is, we can't figure out how to do the error handeling. What we've tried: do { int reloop = 0; try { number = nextInt(); } catch (Exception e) { System.out.println ("Please enter a number!"); reloop ++; } } while(reloop != 0); Only problem is, this loops indefinatly if you enter in something

Remove all vowels in a string with Java

点点圈 提交于 2019-12-09 03:43:21
问题 I am doing a homework assignment for my Computer Science course. The task is to get a users input, remove all of the vowels, and then print the new statement. I know I could easily do it with this code: string.replaceAll("[aeiou](?!\\b)", "") But my instructor wants me to use nested if and else if statements to achieve the result. Right now I am using something like this: if(Character.isLetter('a')){ 'do something' }else if(Character.isLetter('e')){ 'do something else' But I am not sure what

java Scanner reads only first 2048 bytes

感情迁移 提交于 2019-12-08 18:08:06
问题 I'm using java.util.Scanner to read file contents from classpath with this code: String path1 = getClass().getResource("/myfile.html").getFile(); System.out.println(new File(path1).length()); // 22244 (correct) String file1 = new Scanner(new File(path1)).useDelimiter("\\Z").next(); System.out.println(file1.length()); // 2048 (first 2k only) Code runs from idea with command (maven test) /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java -Dmaven.home=/usr/share/java/maven

How to make a ONE static scanner global variable without closing scan constantly and use it within methods and the main method?

十年热恋 提交于 2019-12-08 14:03:27
问题 I want to create a static scanner but i will like to put the try catch block around it so it can automatically close avoiding resources leaks and or this exception: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1585) at softwareEngineer.UserApp1.main(UserApp1.java:82) Essentially I only want to create one static scanner declaration and use it throughout the main program and includes the static methods, at this point my