public static void main(String[] args) {
int largestChain = 0;
for(int i = 1; i < 1000000; ++i) {
if(chain(i) > largestChain) {
largestChain = chain(i); // Here, how do I print the final value
// of 'i' that respects the rule chain(i)?
}
}
System.out.print(largestChain);
}
例如,如果i = 13
,chain(i) = 10
和largestChain
最多13(来自1)是10.现在让我们假设我们有一个周期,从1到100,同一largestChain
的{{1}}仍为10。当周期必须完成其任务(并转到100)时,如何打印i = 13
?
答案 0 :(得分:2)
可能这就是你想要的:
public static void main(String[]args){
int largestChain = 0;
int largestIndex = 0;
for(int i = 1; i < 1000000; ++i){
if(chain(i) > largestChain){
largestChain = chain(i);
largestIndex = i;
}
}
System.out.print("Largest chain is :"+largestChain);
System.out.print("Largest chain index is :"+largestIndex);
}
答案 1 :(得分:1)
int largestChain = 0;
int index =0;
for(int i = 1; i < 1000000; ++i){
if(chain(i) > largestChain){
largestChain = chain(i); //here, how do I print the final value of 'i' that respects the rule chain(i)
index = i;
}
}
System.out.print(largestChain + " index : " + index);