運行通過,但是是亂碼,求解?
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
? ? ? ? int [] scores={89,-23,64,91,119,52,73};
? ? ? ? HelloWorld Score=new HelloWorld();
? ? ? ? Score.qiansan(scores);
?}
?//定義方法完成成績排序并輸出前三名的功能
? ? public void qiansan(int [] scores){
? ? Arrays.sort(scores);
? ? for (int i:scores){
? ? ? ? ? ?if(i>100||i<0){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? int [] aaa=new int[3];
? ? ? ? ? ? for(int j=0;j<=aaa.length-1;j++){
? ? ? ? ? ? ? ? aaa[j]=i;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(aaa);
? ? ? ? }
? ? }
2018-07-01
打印aaa輸出的是各元素的哈希值
2018-07-12
System.out.print(aaa) ? 改成:System.out.print(Arrays.toString(aaa))
如果你不遍歷讀取數組的話,直接輸出得出的就是亂碼,所以轉換成字符串進行輸出即可。
2018-07-03
你的aaa數組賦值之后要遍歷才可以
2018-06-30
import java.util.Arrays;
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld duixiang=new HelloWorld();
? ? ? ? int[] a={89,-23,64,91,119,52,73};
? ? ? ? System.out.println("考試成績前三名為:");
? ? ? ? duixiang.fangfa(a);
? ? }
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void fangfa(int [] a){
? ? ? ? Arrays.sort(a);
? ? ? ? int c=0;
? ? ? ? for(int i=a.length-1;i>=0;i--){
? ? ? ? ? ? if(a[i]>100 || a[i]<0){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? c++;
? ? ? ? ? ? ? ? System.out.println(a[i]);
? ? ? ? ? ? ? ? if(c == 3){
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? }
}
2018-06-30
2018-06-30
試過qiansan調試成qianSan