2017-05-20 38 views
-1
public static void Box() 
{ 
    String[] statement = new String [3]; 
    Censor c = new Censor(); 
    if(response.equalsIgnoreCase(yes)) 
    { 
     System.out.print(name+": >>"); 
     c.Replacement(statement[0]) = input.nextLine(); 
     System.out.println(name+":" + statement[0]); 
     System.out.print(name+": >>"); 
     c.Replacement(statement[1]) = input.nextLine(); 
     System.out.println(name+":" + statement[1]); 
     System.out.print(name+": >>"); 
     c.Replacement(statement[2]) = input.nextLine(); 
     System.out.println(name+":" + statement[2]); 
     if(!statement[2].equals(empty)) 
     { 
      System.out.print(name+": >>"); 
      c.Replacement(statement[0]) = input.nextLine(); 
      System.out.println(name+":" + statement[0]); 
      System.out.print(name+": >>"); 
      c.Replacement(statement[1]) = input.nextLine(); 
      System.out.println(name+":" + statement[1]); 
      System.out.print(name+": >>"); 
      c.Replacement(statement[2]) = input.nextLine(); 
      System.out.println(name+":" + statement[2]); 
     } 
    } 
} 

以上是尝试调用Censor类,并在每个输入中使用方法“替换”,以便用“****”替换Censor类中指定的单词。为什么这个班级电话不工作?

我使用的编译程序特别说明了“Censor c = new Censor();”是不可能的,因为它找不到“符号:班级审查员”。这可能只是由于程序本身,但我只需要确定它是如何写这个问题的问题。

这里是有问题的Censor类。

public class Censor 
{ 
    public static void main(String[] args) 
    { 
    } 
    public static void Censore(String[] statement) 
    { 
     String[] words = new String[3]; 
     Scanner blah = new Scanner(System.in); 
     words[0] = statement[0]; 
     words[1] = statement[1]; 
     words[2] = statement[2]; 
     String replaceString = ""; 
     int loopcount = 0; 
     while(loopcount < 1) 
     { 
      replaceString = words[0].replace("Blank", "****"); 
      replaceString = words[0].replace("Seer", "****"); 
      replaceString = words[0].replace("Nyah", "****"); 
      System.out.println(replaceString); 
     } 
    } 
} 

Editted只是为了摆脱的脏话

+0

您是否导入了类审查员? –

+0

我不认为我做过......你所做的只是放入“进口检查员”;在课程名称正确之前? – Kat

回答

0

关于类如果在另一包则需要使用 Import packagename.classname你叫

c.Replacement(statement[0]) 

和。另一个事情导入您的方法是

Censore(String[] statement)

0

c.Replacement(statement[0]) = input.nextLine(); 

无效。您不能在任务左侧有方法调用。如果你试图分配给statement[0]应用您Replacement方法的input.nextLine()结果的结果,正确的说法是

input.nextLine[0] = c.Replacement(input.nextLine()); 

此外,作为@Omar指出,你实际上并没有一种称为ReplacementCensor类中。但是,您确实有Censore,因此您需要将Censore重命名为Replacement或将所有对Replacement的引用更改为Censore

事实上,因为Censore/ReplacementCensor类的static方法,你不需要为了称之为Censor对象。你可以写,例如

input.nextLine[0] = Censor.Replacement(input.nextLine()); 

然后你根本不需要Censor c = new Censor();。您仍需要理清需要导入Censor类的可能问题,但是...