我有一个从最小值到最大值的范围。 我想通过计算为每个这些值生成一组信息。 我想通过打印输出这些信息。JAVA循环并为条件内的每个值生成输出
如何产生这个输出给定一个循环将只输出一次范围内的一个值的信息?
编程经验 - 绝对初学者。
以下是代码: 基本上,如果用户输入1,我输出所有min2值的信息。 否则,我只输出min2的集合及其probB为1/2的信息。 另外,我可以只使用min1(来自用户输入),而不分配给min2吗?
int prompt = Integer.parseInt(input); // user input
int min2 = 0;
double probB = 0;
for (min2 = min1; min2 < max1; min2++) // for loop
{
if (prompt==1){
int R = 0;
double Rlow = 0;
double Rhigh = 0;
R = (int) (Math.sqrt(2) + 1)*min2;
Rlow = (Math.sqrt(2)+1)*min2+ 1;
Rhigh = (Math.sqrt(2)+1)*min2;
System.out.println(min2);
System.out.print(""+Rlow+""+Rhigh);
System.out.println(R);
probB = (R/R+min2)*(R-1/R+min2-1);
System.out.println(probB);
}
else {
int R = 0;
double Rlow = 0;
double Rhigh = 0;
R = (int) (Math.sqrt(2) + 1)*min2;
Rlow = (Math.sqrt(2)+1)*min2+ 1;
Rhigh = (Math.sqrt(2)+1)*min2;
probB = (R/R+min2)*(R-1/R+min2-1);
if (probB == 1/2){
System.out.println(min2);
System.out.println(""+Rlow+""+Rhigh);
System.out.println(R);
System.out.println(probB);
}
}
}
你能告诉我们你现在的代码吗?也许我们可以指出它的错误。 – Mysticial
[for for语句](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html)和[PrintStream](http://docs.oracle.com/javase/7/docs/ api/java/io/PrintStream.html) – user1329572
具体如我可以...基于问题的彻底性:'for(int i = min; i <= max; i ++){System.out.println(计算(ⅰ)); }' –