考慮數字的順序是這樣的:打印沒有連續重複的數字序列?
1 2 2 5 5 5 1 7 3 7 7 7
輸出應該是
1 2 5 1 7 3 7
我的代碼的電流輸出爲
1 2 5 1 7 3
我無法來解決這個問題。任何人都可以告訴我,我應該怎麼做或更改我的代碼?
這裏是我當前的代碼:
public class Q3 {
public static void main(String args[]) {
int [] input=new int[]{1 ,2, 2, 5, 5, 5, 1, 7, 3, 7, 7, 7};
int current= input[0];
boolean found=false;
for(int i=0; i< input.length; i++) {
if(current == input[i] && !found) {
found=true;
} else if(current!=input[i]) {
System.out.print(" " + current);
current=input[i];
found=false;
}
}
}
}
歡迎SO。你能對這個問題更具體嗎? – arunmoezhi 2014-10-03 05:21:55
打印第一次出現,並忽略其餘的... – MadProgrammer 2014-10-03 05:22:39
@RuchiraGayanRanaweera。這個問題是如何看待由MadProgrammer完成的編輯 – arunmoezhi 2014-10-03 05:25:55