我想創建一個程序,用於統計用戶輸入 (例如, 121221315如何拆分整數(從用戶輸入發生整數)
0:0次
1:4次
2:3次
3:1次
4:0次...等,直到9 .. 。
但我的代碼讀取eg 121221315作爲一個整數,我需要找到一種方法,可以拆分每個整數
另一個問題是,我不知道如何停止第一個for循環...我不知道要放在哪個條件當程序完成讀取輸入時如何停止循環...我剛開始學習編碼..請幫助我簡單/簡單的代碼!
我有下面的代碼
import java.util.Scanner;
public class Occurrence {
\t
\t public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] number = new int[100];
System.out.print("Enter the integers between 1 and 100: ");
for (int i = 0; i < number.length; i++) {
int a = input.nextInt();
number[a] += a;
break;
}
for (int i = 1; i < number.length; i++) {
if (number[i] != 0) {
if (number[i]/i > 1)
System.out.println(i + " occurs " + number[i]/i + " times");
else
System.out.println(i + " occurs " + number[i]/i + " time"); }
}
}
}
關於javascript java的東西是什麼?那不是javascript。這是java! –