【发布时间】:2019-09-26 05:04:34
【问题描述】:
我正在尝试一些关于 coderbyte 的编程挑战并在我自己的 IDE 中编程,因为它更容易,但我不知道为什么它提供的代码甚至可以编译。
import java.util.*;
import java.io.*;
class Main {
public static String MaximalSquare(String[] strArr) {
// code goes here
/* Note: In Java the return type of a function and the
parameter types being passed are defined, so this return
call must match the return type of the function.
You are free to modify the return type. */
return strArr[0];
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(MaximalSquare(s.nextLine()));
}
}
我明白了
线程“主”java.lang.Error: Unresolved compilation problem 中的异常:
Main类型中的方法
MaximalSquare(String[])不是 适用于参数(字符串)
当我尝试在自己的计算机上编译它时,这是我所期望的,因为它试图将字符串传递给 MaximalSquare(String[] strArr),但我不知道为什么它在 coderbyte 上编译得很好
【问题讨论】:
-
MaximalSquare 在 coderbyte 中是否具有相同的签名,它们是否使用可变参数而不是显式数组?
-
看起来Coderbyte并没有真正编译程序,而是直接调用了“参数测试”框中的参数传入的方法。有点遗憾的是,
Guaranteed to Make You a Better Coder网站上的第一个挑战有一个以大写字母开头的方法! -
它看起来更像是 thcoderbyte 的
Scanner被篡改以应对该挑战:nextLine()有返回一个字符串数组(例如[Ljava.lang.String;@74a14482),如果为给定的挑战赛跑(其他都是正常) - 这不会有助于提高你的编码技能(至少你习惯了非常奇怪的行为和错误) -
其实很混乱;在第一个挑战中,如果我将输入从
8更改为8 4我会收到很多 compile 错误,例如:')' expected System.out.print(FirstFactorial(8 4));- 看起来整个代码是预编译的,并且 Scanner 调用被替换为输入值(代码似乎已编译,但不是 raw 输入代码) -
@test - 结论:使用/信任您的本地 IDE;不是编码器字节
标签: java compilation