当前位置: 动力学知识库 > 问答 > 编程问答 >

Java Scanner Support in c9.io?

问题描述:

EDIT

In C9, You have to configure your own runner/builder for Java. If asked for, I'll post my runner/builder if necessary.

I looked up an example script for using Scanner in Java. I use a site called Cloud9 for my code, scripts, etc., and I seem to have run into an issue.

I don't know if Cloud9 doesn't support it, but I got this example code for using Scanner, and it throws some weird error at me.

The Code

import java.util.Scanner;

class GetInputFromUser

{

public static void main(String args[])

{

int a;

float b;

String s;

Scanner in = new Scanner(System.in);

System.out.println("Enter a string");

s = in.nextLine();

System.out.println("You entered string "+s);

System.out.println("Enter an integer");

a = in.nextInt();

System.out.println("You entered integer "+a);

System.out.println("Enter a float");

b = in.nextFloat();

System.out.println("You entered float "+b);

}

}

The Console

Running GetInputFromUser.java

Enter a string

Exception in thread "main" java.util.NoSuchElementException: No line found

at java.util.Scanner.nextLine(Scanner.java:1585)

at GetInputFromUser.main(GetInputFromUser.java:14)

Is it something to do with the C9 IDE or am I doing something wrong?

网友答案:

How does Cloud9 handle standard input? Because that's the error you get when Scanner hits end-of-file:

$ java GetInputFromUser </dev/null
Enter a string
Exception in thread "main" java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Scanner.java:1516)
    at GetInputFromUser.main(GetInputFromUser.java:14)
分享给朋友:
您可能感兴趣的文章:
随机阅读: