这个代码是一个类,它在屏幕上垂直显示我的名字,每个字母使用我输入的最多 5 行 5 列的字符,每个字母之间有一个空行。
它工作得很好,但问题是我对字符串使用了静态,我的教授说代码中的任何地方都不应该是静态的,而是主要的。当我从字符串 c 中删除静态时,即使声明字符串 c,它也会破坏代码内部主要
public class Lab3
{
static String c;
public static void main(String[] args)
{
Lab3 classy = new Lab3();
Scanner input = new Scanner(System.in);
System.out.print("Which character would you like to display?");
c = input.next();
System.out.println("My name is Jonathan");
classy.displayLetterJ();
classy.displayLetterO();
classy.displayLetterN();
classy.displayLetterA();
classy.displayLetterT();
classy.displayLetterH();
classy.displayLetterA();
classy.displayLetterN();
}//end of main
public void displayLetterJ()
{
System.out.println(" " + c + c + c);
System.out.println(" " + c);
System.out.println(" " + c);
System.out.println(c + " " + c);
System.out.println(c + c + c + c + c);
}
public void displayLetterA()
{
System.out.println();
System.out.println(" " + c);
System.out.println(" " + c + " " + c);
System.out.println(" " + c + " " + c + " " + c);
System.out.println(c + " " + c);
System.out.println(c + " " + c);
}
public void displayLetterO()
{
System.out.println();
System.out.println(" " + c + c);
System.out.println(" " + c + " " + c);
System.out.println(c + " " + c);
System.out.println(c + " " + c);
System.out.println(" " + c + c);
}
public void displayLetterN()
{
System.out.println();
System.out.println(c + " " + c);
System.out.println(c + " " + c + " " + c);
System.out.println(c + " " + c + " " + c);
System.out.println(c + " " + c + c);
System.out.println(c + " " + c);
}
public void displayLetterH()
{//H accessor
System.out.println();
System.out.println(c + " " + c);
System.out.println(c + " " + c);
System.out.println(c + c + c + c + c);
System.out.println(c + " " + c);
System.out.println(c + " " + c);
}
public void displayLetterT()
{
System.out.println();
System.out.println(c + c + c + c + c);
System.out.println(" " + c);
System.out.println(" " + c);
System.out.println(" " + c);
System.out.println(" " + c);
}
}