2012-03-09 4 views
0
// Create a class called Dog containing two String: name and says. In main(), create two dogs objects 
and assign it to spot's object. 

class Dog { 
    String name; 
    String says; 
} 

public class DogSays { 
    public static void main(String[] args) { 
     Dog D1 = new Dog(); 
     Dog D2 = new Dog(); 

     D1.says = "Woof!"; 
     D1.name = "Scruffy!"; 

     D2.says = "Bark!"; 
     D2.name = "Spot!"; 
     System.out.println("Hi! My name is " + D1.name); 
     System.out.println(D1.says); 
     System.out.println("Rooooooooowr! I'm " + D2.name); 
     System.out.println(D2.says); 
    } 
} 

나는 한 시간 동안 이것을 확인해 왔으며 무엇이 잘못된 것인지 전혀 모른다. 나는 클래스, 열거 형, 또는 인터페이스 오류가 예상되고 또한 닫히지 않은 문자 리터럴을 얻는다. 제 생각에 그것은 따옴표가있는 것으로 생각합니다.닫지 않은 문자 리터럴

+0

코드가 컴파일되었습니다. –

+0

코드가 잘 작동하고 있는데, 무엇이 문제입니까? 오류를 게시 할 수 있습니까 ?? –

+0

출력이'안녕하세요! 내 이름은 초라한이야! 위! Rooooooooowr! 나는 스팟이야! 나무 껍질! –

답변

2

문제 "닫히지 않은 문자 리터럴은"여기에 있습니다 :

//Exercise2.5 Create a class called Dog containing two String: name and says. In main(), create two dogs objects 
and assign it to spot's object. 

그것을 확인 : 당신은 //을 선행 또는 /**/쌍로 묶여 있지 않고 부유 의견이 없습니다

//Exercise2.5 Create a class called Dog containing two String: name and says. In main(), create two dogs objects 
//and assign it to spot's object. 

..

+0

고마워요! 나는 단지 2 시간의 나의 인생을 낭비하는 것처럼 느낀다 :( – CrewdNBasic

1

마음에 떠오르는 유일한 점은 다음과 같습니다.

//Exercise2.5 Create a class called Dog containing two String: name and says. In main(), create two dogs objects 
and assign it to spot's object. 

정확하게 수업에서 작성한 방법이면 댓글의 두 번째 줄에 and assign it to spot's object.이라는 오류가 표시됩니다. 자바에서 // 한 줄 주석을 의미한다, 그래서 당신은이 작업을 수행 중 하나를해야합니다 :

//Exercise2.5 Create a class called Dog containing two String: name and says. In main(), create two dogs objects 
//and assign it to spot's object. 

하거나 다른 텍스트는 //을 다음과 컴파일러에 지시하는 // 반대로

/*Exercise2.5 Create a class called Dog containing two String: name and says. In main(), create two dogs objects 
and assign it to spot's object. */ 

주석이므로 무시할 수있는 동일한 행에 있습니다. /* */ 문자는 임의의 수의 행을 확장 할 수있는 주석 블록을 나타냅니다.

관련 문제