Amount of Arrays created depends on input; How to debug?

huangapple go评论111阅读模式
英文:

Amount of Arrays created depends on input; How to debug?

问题

我一直在解决一些USACO指南中的铜牌问题,但在我的代码中遇到了两个错误;一个是运行时错误,另一个是逻辑错误。

任务是超速罚单,输入了行驶的英里数/速度限制,然后输入了实际行驶的英里数/速度,然后让我找到超速的最大英里数。

运行时错误似乎发生在询问用户输入的某个地方,但我以前用过相同的方法,那时什么都没发生,所以我不知道哪里出错了。

至于第二个错误,虽然没有明确说明,但我知道这是我代码中的一个错误。问题是,我实际上不知道如何实现它。我知道如果我需要创建的配对数是一个固定的值,我会怎么做,但在这里它取决于用户的输入。所以在这方面我陷入了困境。

我的代码链接在replit上
预期输出:5
实际输出:错误

任何帮助将会很棒!
1: https://i.stack.imgur.com/LVgXv.png

英文:

I've been working on some USACO guide Bronze problems when I ran into two errors in one of my codes; a runtime error and a logic error.

The task, Speeding Ticket, inputs the miles traveled/speed limit and then the miles traveled/speed actually went and asks me to find the greatest number of mph that the speed limit was exceeded by.

The runtime error seemed to occur somewhere while asking for user input, but I've used the same method before and nothing happened then so I don't know where I'm going wrong.

As for the second one, thought it hasn't explicitly been said, I know this is an error in my code. The problem is, I actually don't know how to implement it. I know what I'd do if the number of pairs I needed to create was a fixed value, but here it depends on user input. So I'm stuck in that regard as well.
Link to my code on replit

What I expected: 5
What I got:error

Any help would be great!

答案1

得分: 2

你的javac命令运行编译器。编译器在你的代码中发现了一个 可能的 错误,但是,你的代码在技术上是可以编译的。只是有点奇怪。因此,它告诉你:好的,我已经编译了你的代码,但是,你应该仔细查看这个问题,因为我真的非常怀疑你的意思是你所写的。这就是:

> 注意:重新编译时使用 -Xlint 以获取详细信息

的意思。

你应该再次调用javac,并添加-Xlint(或者始终添加-Xlint)来告诉编译器更多关于它发现的内容。

相反,你运行了 你的应用程序 并将-Xlint传递给 你的应用程序。你的应用程序将所有参数解析为数字,显然-Xlint不是一个数字,因此你的应用程序会提前退出,因为尝试将-Xlint解析为数字导致的异常已经传播到了最顶层。

我怀疑 replit 并没有这样做。如果是这样,你可以给 replit 的工作人员发邮件,告诉他们他们的代码运行系统中存在一个错误。对此,stackoverflow 或你都无能为力 - 可能你可以通过确保不再出现警告来解决这个问题。

然而,更有可能的情况是 在运行你截图中的内容。在这种情况下,请不要将-Xlint传递给java - 你应该将其传递给javac

英文:

Your javac call runs the compiler. The compiler found a likely bug in your code, but, your code is technically compilable. Just, weird. Hence, it tells you: Okay, I did compile your code, but, you should probably have a closer look at this thing because I really really doubt you meant what you wrote. That's what:

> Note: recompile with -Xlint for details

is about.

You are supposed to invoke javac a second time and add -Xlint (or just always add -Xlint) to tell the compiler to tell you far more about what it found.

Instead, you ran your application and passed -Xlint to your application. Your app parses all arguments as numbers, -Xlint obviously isn't a number, and therefore your app exits early because the exception caused by trying to parse -Xlint as number bubbled to the top.

I doubt replit is doing that. If so, you mail the replit staff and tell them they have a bug in their code runner system. There's nothing stack overflow, or you, can do about it - possibly you can work around it by ensuring that warning no longer happens.

However, it sounds vastly more likely that you are running the stuff in your screenshot image. In which case, don't pass -Xlint to java - you pass that to javac.

huangapple
  • 本文由 发表于 2023年7月31日 21:23:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定