2017-05-20 5 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 클래스를 호출하고 각 입력에 "Replacement"메서드를 사용하여 Censor 클래스에 지정된 단어를 "****"로 바꿉니다.이 클래스 호출이 작동하지 않는 이유는 무엇입니까?

내가 사용하는 컴파일 프로그램은 구체적으로 "Censor c = new Censor();"라고 말합니다. "symbol : class Censor"를 찾을 수 없으므로 불가능합니다. 프로그램 자체 때문일 수도 있지만, 필자가 작성한 방법으로 문제가 발생했는지 확인해야합니다.

여기 Censor 클래스가 있습니다. 다른 패키지에 당신은 당신이

c.Replacement(statement[0]) 

및 전화 Import packagename.classname .Another 일을 사용하여 가져와야의 경우 클래스에 대해서

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); 
     } 
    } 
} 

편집 해 그냥 없애 맹세 단어

+0

Censor 클래스를 가져 왔습니까? –

+0

나는 생각하지 않는다 ... 당신이하는 모든 것은 "수입 검열"이다. 수업 이름 전에 말이야? – Kat

답변

0

당신의 방법은

Censore(String[] statement)

0

증언 내용

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

은 유효하지 않습니다. 과제의 왼쪽에는 메소드 호출을 할 수 없습니다. 당신이 statement[0]input.nextLine()의 결과에 Replacement 방법을 적용한 결과를 할당하려고 한 경우 올바른 문장은 @Omar가 지적한대로, 당신이 실제로하는 방법은 Replacement라고하지 않아도, 또한

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

입니다 Censor 클래스에 있습니다. 그래도 Censore이 있으니 CensoreReplacement으로 바꿔야하거나 Replacement을 모두 Censore으로 변경해야합니다. Censore/Replacement 클래스 Censorstatic 방법이기 때문에 사실

는, 당신은 그것을 호출하기 위해 Censor 객체가 필요하지 않습니다. 예를 들어 쓸 수 있습니다.

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

그러면 Censor c = new Censor();은 전혀 필요하지 않습니다. 그러나 Censor 클래스를 가져올 필요가있는 문제를 해결해야합니다 ...

관련 문제