我必须制作一个代码,使一个星球大战的名称生成器,它要求名称,但只需要从名称中的某些字母提出星球大战的名称,我的程序不会编译任何人都可以看到我做错了什么:
import java.util.Scanner;
public class StarWarsName {
public static void main(String[] args) {
System.out.printf("Enter your first name: ");
firstname = input.nextLine();
first = first.substring(0,3);
System.out.printf("Enter your last name: ");
lastname = input.nextLine();
last = last.substring(0,2);
System.out.printf("Enter your mother's maiden name: ");
mothersname = input.nextLine();
mother = mother.substring(0,2);
System.out.printf("Enter the name of the city in which you were born: ");
cityname = input.nextLine();
city = city.substring(0,3);
StarWarsName = first +" "+ last +" "+ mother +" "+ city + " of " + last +" "+$
System.out.println("May the force be with you, " + StarWarsName + "May the fo$
}
}
答案 0 :(得分:2)
从这一行开始:
firstname = input.nextLine();
提示:
1)firstname
在哪里宣布?
2)阅读编译错误消息!
3)当你向别人询问有关编译错误的问题时,你需要说明编译错误是什么,以及编辑错误发生的位置。
考虑这一行:
StarWarsName = first +" "+ last +" "+ mother +" "+ city + " of " + last +" "+$
4)最后的$
不是有效的Java。它看起来像一个复制和粘贴错误。如果Java程序中的一行太长而无法放在您的(预期)显示设备上,那么将它拆分为常规练习; e.g。
StarWarsName = first +" "+ last +" "+ mother +" "+ city + " of " +
last + " " + and + " " + the + " " + rest;
答案 1 :(得分:0)
您有几个未声明的变量,例如firstname
。我认为还有一些逻辑错误,因为你不使用firstname
和其他人。