調(diào)試不出來,求大神指點(diǎn)
package com.imooc;
import java.util.Arrays;
import java.util.Scanner;
public class chengji {
//尚未調(diào)試成功,進(jìn)行有效性判斷,并輸出排名前三位
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] score={1,30,30,56,120,45};
chengji d=new chengji();
int f [] =d.youxiao(score);
}
public int[] youxiao(int[] b){
int c=0;
int[] num=new int[6];
for(int i=0;i<b.length;i++){
if(b[i]>0&&b[i]<100){
b[c]=b[i];
c++;}
}
int[] n=new int[c];
int d=0;
for(int i=0;i<=c;i++)
{d=num[i];
n[i]=d;}
return n;
}
}
2017-04-30
樓主是不是學(xué)了C語言的,java語言不是這樣的
2017-04-15
一個(gè)類里的其他方法的方法名好像有問題,比如public int[] ? youxiao(int[] b){...},
!!!樓主!!!你覺得這到底是什么?
這個(gè)方法的方法名是什么?有返回值在里面??
恕我是鄉(xiāng)下人,下面其他方法我看不懂
不過你在主方法main里有int f [] =d.youxiao(score);你用對(duì)象d調(diào)用方法youxiao帶入?yún)?shù)score,
【1】所以在public int[] ? youxiao(int[] b){...}里面youxiao才是方法名,
那么在public ?int[] ?youxiao(int[] b){...}里第一個(gè)int[]是什么?
【2】還有你在創(chuàng)建類前面的導(dǎo)入(import) 里面的 ?包(java.util.)的各種工具Arrays還有Scanner;你在下面都沒有用到。
樓主啊~??!給你一句話:基礎(chǔ)很重要,然后再來一遍。
2017-04-12
package com.hwadee.chengji;
import java.util.Arrays;
public class ChengJi {
? ??
? ? // 尚未調(diào)試成功,進(jìn)行有效性判斷,并輸出排名前三位
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? int[] score = { 1, 30, 30, 56, 120, 45 };
? ? ? ? ChengJi d = new ChengJi();
? ? ? ? int f[] = d.youXiao(score);
? ? ? ? for (int i = 0; i < f.length; i++) {
? ? ? ? ? ??
? ? ? ? ? ? System.out.println(f[i]);
? ? ? ? }
? ? }
? ??
? ? public int[] youXiao(int[] b) {
? ? ? ? int[] num = new int[3];
? ? ? ? Arrays.sort(b);
? ? ? ? for (int i = 0; i < num.length; i++) {
? ? ? ? ? ??
? ? ? ? ? ? num[i] = b[b.length - 1 - i];
? ? ? ? }
? ? ? ? return num;
? ? ? ??
? ? }
? ??
}
可以直接通過數(shù)組的sort方法升序排序獲得