gpt4 book ai didi

java - 运行扫描仪程序

转载 作者:行者123 更新时间:2023-12-01 23:09:06 25 4
gpt4 key购买 nike

我正在尝试编写一个程序,该程序基本上可以读取 1,000 到 999,999 之间的任何整数,然后用逗号分隔千位来显示它。到目前为止我已经有了这个,而 eclipse 不喜欢它。为什么?

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// Scanner scan = new scanner(system.in);
double value, integer;
System.out.println("Enter your value without a comma");
integer = scan.nextdouble();
System.out.println(integer,);
scan.close();

最佳答案

代码中有很多错误,这就是 Eclipse 不喜欢它的原因;)

仅举几例:

  • 新扫描仪 -> 大写 S 扫描仪
  • system.in -> 与系统相同

看看下面的这段代码,它会运行得很好:)

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone {

public static void main(String[] args) throws java.lang.Exception {

Scanner scan = new Scanner(System.in);

double value, intValue;

System.out.println("Enter your value without a comma");

intValue = scan.nextDouble();

System.out.println(intValue);

scan.close();
}

关于java - 运行扫描仪程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com