How can i insert multiple input in one line in 2dArray looping

So i want my output to be something like this: N = 3 userinput1 | userinput2 | userinput3 userinput4 | userinput5 | userinput6 userinput7 | userinput8 | userinput9 but the problem is after i insert my userinput1 and press enter it goes one space below and become like this 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | i tried to change sc.nextInt(); to sc.nex

如何在2dArray循环中的一行中插入多个输入

所以我想我的输出是这样的: N = 3 userinput1 | userinput2 | userinput3 userinput4 | userinput5 | userinput6 userinput7 | userinput8 | userinput9 但问题是我插入我的userinput1并按下输入它下面的一个空间,并成为这样 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 我试图改变sc.nextInt(); sc.nextLine(); 但它不工作,即使我使用parseInt .. public static void

Using a scanner in a non

I have a code that searches for words in a text file, but the scanner that runs it is located in the public static void main(String[] args) for the class. I need to be able to move the scanner into a string, so that rather than inputting the word that I want to search for in the code manually as a word in quotes, I can find it by referencing the string in another class's main method, with a

使用非扫描仪

我有一个代码在文本文件中搜索单词,但运行它的扫描器位于该类的public static void main(String [] args)中。 我需要能够将扫描器移动到一个字符串中,这样,我就可以通过引用另一个类的主要方法中的字符串来找到它,而不是在代码中手动输入要在代码中搜索的单词,用一个构造函数接受文字。 但是,当我尝试将扫描器移出主体并进入新的公共字符串时,我必须更改System.out.println(arr [0])以返回arr [0],并且程序将不会

How to close a scanner without closing the underlying System.in?

If I close one scanner object and make a new one and try to read some more input, I'm getting the NoSuchElementException exception. My code works fine but it gives me a warning if I don't close the scanner. However, if I close it to get rid of the warning, I also close System.in ... How do I avoid this? Also, are there any consequences of not closing the scanner? EDIT: Here's m

如何在不关闭底层System.in的情况下关闭扫描器?

如果我关闭一个扫描器对象并创建一个新对象并尝试读取更多输入, NoSuchElementException收到NoSuchElementException异常。 我的代码工作正常,但如果我不关闭扫描仪,它会给我一个警告。 但是,如果我关闭它来摆脱警告,我也关闭System.in ...我如何避免这种情况? 另外,是否有没有关闭扫描仪的后果? 编辑:这是我的代码: 这是NameAddressExists()方法: public void NameAddressExists() { System.out.print

Java Multiple Scanners

I have a class that creates multiple integer objects onto a linked list as shown below: public class Shares<E> implements Queue<E> { protected LinkedList<E> L; public Shares() { L = new LinkedList<E>(); } public boolean add(E price) { System.out.println("How many of these shares would you like?"); Scanner scanInt; scanInt = new Scanner(System.in); I

Java多个扫描器

我有一个类创建多个整数对象到链表上,如下所示: public class Shares<E> implements Queue<E> { protected LinkedList<E> L; public Shares() { L = new LinkedList<E>(); } public boolean add(E price) { System.out.println("How many of these shares would you like?"); Scanner scanInt; scanInt = new Scanner(System.in); Integer noShares = scanInt.nextInt();

Now am getting incompatible error when using the if else statements

trying to run the program below but am getting an error when using the switch method import java.util.Scanner; /** * * @author kern public class loans { public static void main(String[] args) { Scanner input = new Scanner(System.in); //variabled decleared double rate, payment,principal,interest,n; int length; String period; //input System.out.print("Enter the amoun

现在我在使用if else语句时出现不兼容的错误

试图运行下面的程序,但使用开关方法时出现错误 import java.util.Scanner; / ** * * @作者kern公共类贷款{ public static void main(String[] args) { 扫描仪输入=新扫描仪(System.in); //variabled decleared double rate, payment,principal,interest,n; int length; String period; //input System.out.print("Enter the amount of money borrowed: $"); principal = input.nextDouble

Scanner cannot be resolved to a type

I just installed Ubuntu 8.04 and I'm taking a course in Java so I figured why not install a IDE while I am installing it. So I pick my IDE of choice, Eclipse, and I make a very simple program, Hello World, to make sure everything is running smoothly. When I go to use Scanner for user input I get a very odd error: My code: import java.util.Scanner; class test { public static void mai

扫描仪无法解析为某种类型

我刚刚安装了Ubuntu 8.04,并且正在学习Java课程,所以我想知道为什么不在我安装时安装IDE。 所以我选择我选择的IDE,Eclipse,并且我制作了一个非常简单的程序Hello World,以确保一切运行顺利。 当我使用Scanner进行用户输入时,我得到一个非常奇怪的错误: 我的代码: import java.util.Scanner; class test { public static void main (String [] args) { Scanner sc = new Scanner(System.in); Sy

Scanner throws NoSuchElementException

The following code is showing an error. I am very new to coding. This thing is messing with my head. What can I do? I have tried everything I know but nothing has worked out so far. What is the best and most efficient way to code such programs? Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.n

扫描程序抛出NoSuchElementException

以下代码显示错误。 我对编码非常陌生。 这东西正在弄乱我的头。 我能做什么? 我已经尝试了我所知道的一切,但到目前为止没有任何结果。 什么是最好和最有效的方式来编写这样的程序? 线程“主”中的异常 java.util.NoSuchElementException在 java.util.Scanner.throwFor(Scanner.java:862)at java.util.Scanner.next(Scanner.java:1371)at Codechef.main(Main.java:27) 以下代码是在编辑之后。 但它仍

NoSuchElement exception error in particular program

I have used Scanner for all my programming needs, but for some reason, I'm unable to get through this error: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Main.main(Main.java:9)

NoSuchElement特殊程序中的异常错误

我已经使用扫描仪来满足我所有的编程需求,但出于某种原因,我无法解决这个错误: java.util.Scanner.nextInt(java.util.Scanner.nextInt())中java.iotil.Scanner.next(Scanner.java:1485)上的(Scanner.java:862) Scanner.java:2117)在Main.main(Main.java:9)处的java.util.Scanner.nextInt(Scanner.java:2076) 在以下代码中: import java.util.*; import java.lang.*; import java.io.*; class Main { pu

Close a Scanner linked to System.in

I have a Scanner linked to System.in . Now, after using the Scanner , I should close it, as it is bad coding practice to leave it open. But, if I close the Scanner , I will also be closing System.in ! Can anyone tell me how I can close the Scanner without closing System.in (if there is any way). One option is to wrap your System.in stream in a CloseShieldInputStream that prevents it from bei

关闭与System.in链接的扫描仪

我有一个Scanner链接到System.in 。 现在,在使用Scanner ,我应该关闭它,因为打开它是不好的编码习惯。 但是,如果我关闭Scanner ,我也将关闭System.in ! 任何人都可以告诉我如何关闭Scanner而不关闭System.in (如果有任何方法的话)。 一种选择是将System.in流封装到CloseShieldInputStream ,以防止它被关闭。 然后,您的阅读器将使用CloseShieldInputStream而不是原始System.in流。 以下是该类的API:http://com

What is wrong with my scanner code?

Can anybody tell me what is wrong with my code as shown below? The first case works perfectly fine but the second and third case throws an exception : Does this have something to do with the while loops at the start of case 2 and 3? public static void main(String[] args) { Scanner scan = new Scanner(System.in); int option = scan.nextInt(); switch (option) { case 1: int l

我的扫描仪代码有什么问题?

有人可以告诉我我的代码有什么问题,如下所示? 第一种情况非常好,但第二种和第三种情况引发异常: 这与情况2和3开始时的while循环有什么关系? public static void main(String[] args) { Scanner scan = new Scanner(System.in); int option = scan.nextInt(); switch (option) { case 1: int line = scan.nextInt(); for (int i = 0; i < line; i++){ Str