import java.util.Random;
import java.util.Scanner;
public class ArrayPractice {
public static void main(String[] arg) {
long input;
System.out.println("How Many Times will you roll?");
Random random=new Random();
Scanner scan=new Scanner(System.in);
input=scan.nextLong();
long freq[]=new long[7];
for(long i=1;i<input;i++){
//1+random.nextInt(6)-numbers 1-6
++freq[1+random.nextLong(6)];
}
System.out.println("Face\tFrequency");
for(long i=1;i<freq.length;i++){
System.out.println(i+"\t"+freq[i]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我的程序说他们将++freq[1+random.nextLong(6)];
and freq[i]我的所有值转换为long 是不匹配的.为什么他们会不匹配?
我明白如何ViewHolder的onBindViewHolder作品,但我不清楚如何notifyItemRangeChanged(0, this.data.size());在这个例子中它到底是什么工程和.
提供给此适配器的数据采用Json格式.
适配器如下:
public class AdapterQuestion extends RecyclerView.Adapter<AdapterQuestion.ViewQuestion>{
private LayoutInflater mLayoutInflater;
//this is an arrayList of questionData objects
private ArrayList<QuestionData> data =new ArrayList<>();
//Created the layoutInflator
public AdapterQuestion(Context context){
//get from context
mLayoutInflater=LayoutInflater.from(context);
}
public void setBloglist(ArrayList<QuestionData> data){
this.data =data;
notifyItemRangeChanged(0, this.data.size());
}
@Override
public ViewQuestion onCreateViewHolder(ViewGroup parent, int viewType) {
//inflates the customQuestion view or converts it to java code
View view= mLayoutInflater.inflate(R.layout.customquestion, null);
//We now want to convert the View into …Run Code Online (Sandbox Code Playgroud)