方法调用With参数



本周,在我的大学课堂上,我们开始了关于方法调用的章节,但我遇到了麻烦。这是我们课堂上的活动:定义一个方法printFeetInchShort,使用int参数numFeet和numInches,使用'和";速记例如:myPrinter.printFeetInchShort(5,8(打印:5’8〃;提示:使用";打印双引号。这就是我到目前为止所做的,我不知道我做得是否正确,因为我在方法调用方面遇到了麻烦:

import java.util.Scanner;
public class HeightPrinter {
public static void printFeetInchShort(int numFeet, int numInches) {
System.out.println(numFeet + "" + numInches + """);

public static void main (String [] args) {
HeightPrinter myPrinter = new HeightPrinter();
// Will be run with (5, 8), then (4, 11)
myPrinter.printFeetInchShort(5, 8);
System.out.println("");
}

}

public static void printFeetInchShort(int numFeet, int numInches) {
System.out.print(numFeet + "' " + numInches + """);

您缺少用于关闭printFeetInchShort方法的大括号。

import java.util.Scanner;
public class HeightPrinter {
public static void printFeetInchShort(int numFeet, int numInches) {
System.out.println(numFeet + "' " + numInches + """);
}  //<-- this is missing
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userFeet;
int userInches;
userFeet = scnr.nextInt();
userInches = scnr.nextInt();
printFeetInchShort(userFeet, userInches);  // Will be run with (5, 8), then (4, 11)
}
}

最新更新