1
您用隨機數字編寫代碼應該算出您輸入的唯一數字。例子5545將給出2作爲答案。如果我輸入更多數字,最多可以使用10位數字,我會收到錯誤消息。爲什麼?當輸入多於10位數字時出現矢量錯誤
import java.util.Random;
import se.lth.cs.window.SimpleWindow;
import se.lth.cs.p.ovn.turtle.Turtle;
import java.util.Scanner;
public class p5 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int apa=0;
System.out.println("ange tal");
int tal = scan.nextInt();
boolean hej [] = new boolean[10];
if(tal==0){
hej[0]=true;
System.out.println("awejawejwaejae");
}
while(tal>0){
int z = tal%10;
hej[z]=true;
tal=tal/10;
}
for(int k=0; k<10; k++)
if(hej[k]==true){
apa++;
}
System.out.println(apa);
for(int k=0; k<10; k++){
System.out.println(hej[k]);
}
}
}