【发布时间】:2012-11-01 15:51:43
【问题描述】:
所以我一直在尝试解决这个问题。我尝试过的很多事情都失败了。有没有办法添加到我已经拥有的东西上?
for(int ii = 1, j = 0; j <= copySel ; ii++, j++) {
int check;
int x, y;
// Prompt as follows
System.out.print("Enter value " + ii + ": ");
try {
c = Get();
}
catch (InputMismatchException e) {
input
System.out.println("Invalid input!");
ii--;
}check = c;
x = check; // I want to try to copy this
y = check - 1; // and copy this
min(x , y) // trying to acheive this
System.out.println(check + " " + x + " " + y);
}
对格式问题感到抱歉。这是我的屏幕。
Basically let us say user puts in 25 for first input. I want x = 25.
Then user inputs -11. I want y = -11.
Compare minimum z = -11.
then x = z = -11;
User input 33. y = 33
annd so on..
所以我最终得到了类似的东西
for(int ii = 1, j = 0; j <= copySel ; ii++, j++) {
int check;
int x = 0, y = 0, z;
// Prompt as follows
System.out.print("Enter value " + ii + ": ");
try {
c = Get();
}
catch (InputMismatchException e) {
System.out.println("Invalid input!");
ii--;
}check = c;
x = check;
z = x;
if (j % 2 == 1)
{
y = check;
Math.min(z, y);
}
System.out.println(check + " " + x + " " + y + " " + z);
}
【问题讨论】:
-
你想找到最少两个数字吗?请发布您尝试过的许多事情之一。
-
如果用户决定设置 3 或 4 来比较的话会超过两个
-
你的这个问题没有解决你的问题吗? stackoverflow.com/questions/13356400/…
-
y不会一直是x - 1?计算最小值似乎很愚蠢;在程序的那个时候,它总是y。另外,你想用最小值做什么?把它存放在某个地方? -
你想达到什么目的?不要只是粘贴一些不起作用的代码。解释您想要做什么以及什么(确切地说是错误消息、异常......)不起作用。