看板 java 關於我們 聯絡資訊
假設 原來的 Pos method 是一個無良的SA開出來的 public static int Pos(int[] hw1); 那我會這樣子搞 public static void main(String[] args) { System.out.println("輸入三個數字"); Scanner scn=new Scanner(System.in); int[] hw1=new int[3]; for (int i=0;i<hw1.length;i++) { hw1[i]=scn.nextInt(); } int Pos = Pos(hw1); String strPos = String.valueOf(Pos); if (!"0".equals(strPos)) { for (byte b : strPos.getBytes()) { System.out.println("正數有:"+hw1[(Integer.valueOf(b) - 49)]); } } else { System.out.println("輸入三個數字,沒有正數"); } } public static int Pos(int[] hw1){ String returnInt = "0"; for (int i=0;i<hw1.length;i++) { if (hw1[i] > 0) { returnInt = returnInt + String.valueOf(i+1); } } return Integer.valueOf(returnInt); } -- 假日被叫到公司加班很悶.... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.58.48 ※ 編輯: ssc24 來自: 111.250.58.48 (10/12 17:23)
v3dys6f3a3j5:老實說....我看不懂 不過這也代表你是高手 10/12 19:52
v3dys6f3a3j5:我最近剛學Java 不過還是謝謝你~ 10/12 19:54