2013-04-05 5 views
-1

태그는 질문을 다른 유사한 질문과 함께 분류하는 키워드 또는 레이블입니다. 태그는 유사한 질문과 함께 질문을 분류하는 키워드 또는 레이블입니다.정렬 배열이 작동 할 수있는 방법을 얻을 수 없습니다.

+0

'x Maroun

+0

사용자가 listNames 프롬프트를 표시합니다. –

+0

'int' (x)를 문자열 배열 (sort)과 비교할 수 없습니다. 정렬의 길이를'sort.length'와 비교해 보았을 것입니다. – Maroun

답변

0

당신은

for (int x = 0; x < sort; x++) 

대신

for (int x = 0; x < sort.length; x++) 

에 변경해야합니다.

String[] sort = new String[listNames]; 

또한

String[] sort = new String[listNames.length]; 

하고, JOptionPane.showMessageDialog()이 방법으로 사용되어야한다 : 내가 먼저 다음 라인을 작성하고 있습니다 다음과 같은 세 가지 코드 블록에서

JOptionPane.showMessageDialog(null," Tutor LAST NAME and FIRST NAME Listed in Alphabetically Order"+(x+1)+ " " + "For example: 'Smith, John'"); 
+0

내가 바로 atleast 또는 atleast 순서 또는 오른쪽 트랙에 –

+0

와우 도와주세요!. 오류 : 나만 PeerTutorReport.java:46 지금 하나의 에러가 발현 용 \t \t 불법 개시 INT (X = 0, X

+0

PeerTutorReport.java:49 : 오류 : showMessageDialog (String)에 적합한 메소드가 없습니다. \t \t sort [x] = JOptionPane.showMessageDialog ("교사 마지막 이름 및 첫 번째 이름 알파벳 순서로 나열 "+ (x + 1) +" "+"예 : 'Smith, John' "); –

1

무엇을

String[] sort = new String[listNames]; 
String[] sort = new String[listNames.length]; 
            ^^^^^^^ 
당신에게 돈이 방법해야하는 경우

public static String[] sortNames(String[] listNames) { 
    String[] copy = Arrays.copyOf(listNames, listNames.length); 
    Arrays.sort(copy); 
    return copy; 
} 

,하지만 당신이 정말로 이전을 정렬에 새로운 배열을 만들려면 가정

for (int x = 0; x < sort; x++) { 
for (int x = 0; x < sort.length; x++) { 
         ^^^^^^^ 

sort[x] = JOptionPane.showMessageDialog(" Tutor LAST NAME and FIRST NAME Listed in Alphabetically Order"+(x+1)+ " " + "For example: 'Smith, John'"); 
sort[x] = JOptionPane.showMessageDialog(null, " Tutor LAST NAME and FIRST NAME Listed in Alphabetically Order"+(x+1)+ " " + "For example: 'Smith, John'"); 
             ^^^^^ 

, 당신의 방법이 있어야한다 두 번째 배열을 만들어야 할 경우 다음을 수행 할 수 있습니다.

public static void sortNames(String[] listNames) { 
    Arrays.sort(listNames); 
} 
관련 문제