gpt4 book ai didi

java - 编写静态 void 方法 - "cannot find symbol"编译错误

转载 作者:行者123 更新时间:2023-12-01 17:16:16 30 4
gpt4 key购买 nike

这是我的作业:

编写一个名为greeting的静态void方法,它带有三个字符串参数,该方法按以下格式格式化和打印标题、名字和姓氏,然后将其打印出来。

blank line
Dear title first name last name,
blank line

到目前为止,我编写了这段代码:

import java.io.*;
import java.util.Scanner;
public class GreetingLab {
public static void main(String[] args) throws IOException {
String title;
String firstName;
String lastName;
Scanner in;
in = new Scanner(System.in);
System.out.print("Enter a title:");
title = in.next();
System.out.print("Enter your first name:");
firstName = in.next();
System.out.print("Enter a your last name:");
lastName = in.next();
greeting(title,firstName,lastName);
}
private static void greeting (String ttl, String fName, String lName)
{
System.out.println();
System.out.println ("Dear "+ttl+" "+fName+" "+lname+",");
System.out.println();
}
}

但它一直给我这个错误:

1 error found:
File: /Users/chanelkinard/Desktop/GreetingLab.java [line: 21]
Error: /Users/chanelkinard/Desktop/GreetingLab.java:21: cannot find symbol
symbol : variable lname
location: class GreetingLab

这是上述代码的第 21 行:

System.out.println ("Dear "+ttl+" "+fName+" "+lname+",");

最佳答案

Java 区分大小写 - 更改 println 参数以匹配方法参数

System.out.println("Dear " + ttl + " " + fName + " " + lName + ",");
^

关于java - 编写静态 void 方法 - "cannot find symbol"编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21943025/

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