如何让程序做一些数学运算! [英] How to make a program do some maths!
问题描述
你好,我正在尝试编写一个解决联立方程的程序。它遍历x的所有可能性,如果它们中的任何一个满足y的条件,则显示它。我的问题是我不知道如何制作它只显示正整数。我所做的是改变一个双值整数,然后显示它,但它只是小数点的切割,不给我所有可能的x和y是整数而不是舍入。
这是我的代码
[code]
class Maths {
public static void main(String [] args){
for(int y = 10; y< = 92; y ++){
double a = Math.sqrt((y * y)+180);
int x =(int)a;
System.out.println(x +"" + y +"");
} < br $>
}
}
[代码]
感谢任何帮助
Hello, I am trying to write a program to solve a simultaneous equation. It runs through all the possibilites for x, and if any of them forfil the conditions of y, then it is displayed. My problem is that i don''t know how to make it so that only positive integers are displayed. What I have done was change a double value integer, and then display that, but all it does it cut of the decimals, not give me all the possibles for x and y that are whole numbers without being rounded.
Here is my code
[code]
class Maths {
public static void main (String[] args) {
for (int y = 10; y <= 92; y++){
double a = Math.sqrt((y*y)+180);
int x = (int)a;
System.out.println(x + " " + y + " ");
}
}
}
[code]
Thanks to anyone who helps
推荐答案
您好,我正在尝试编写一个程序来解决联立方程式。它遍历x的所有可能性,如果它们中的任何一个满足y的条件,则显示它。我的问题是我不知道如何制作它只显示正整数。我所做的是改变一个双值整数,然后显示它,但它只是小数点的切割,不给我所有可能的x和y是整数而不是舍入。
这是我的代码
[code]
class Maths {
public static void main(String [] args){
for(int y = 10; y< = 92; y ++){
double a = Math.sqrt((y * y)+180);
int x =(int)a;
System.out.println(x +"" + y +"");
} < br $>
}
}
[代码]
感谢任何帮助
的人
Hello, I am trying to write a program to solve a simultaneous equation. It runs through all the possibilites for x, and if any of them forfil the conditions of y, then it is displayed. My problem is that i don''t know how to make it so that only positive integers are displayed. What I have done was change a double value integer, and then display that, but all it does it cut of the decimals, not give me all the possibles for x and y that are whole numbers without being rounded.
Here is my code
[code]
class Maths {
public static void main (String[] args) {
for (int y = 10; y <= 92; y++){
double a = Math.sqrt((y*y)+180);
int x = (int)a;
System.out.println(x + " " + y + " ");
}
}
}
[code]
Thanks to anyone who helps
写一个带有double的isInteger方法。
提示:如果用不表示整数的字符串调用Integer.parseInt,则会得到NumberFormatException 。
Write an isInteger method that takes a double.
Hint: If you call Integer.parseInt with a string that does not represent an integer, you get a NumberFormatException.
写一个isInteger方法,需要一倍。
提示:如果使用不表示整数的字符串调用Integer.parseInt,则会得到NumberFormatException。
Write an isInteger method that takes a double.
Hint: If you call Integer.parseInt with a string that does not represent an integer, you get a NumberFormatException.
谢谢 - 很抱歉,但是因为我是java的新手(一周前开始)你能告诉我代码以及把它放在哪里吗? br />
感谢您的帮助
Thanks - sorry to ask, but as i''m new to java (started a week ago) could you show me the code and where to put it?
Thanks for your help
谢谢 - 不好意思,但是因为我是java的新手(一周前开始)你能告诉我代码和放在哪里吗?
感谢你的帮助
Thanks - sorry to ask, but as i''m new to java (started a week ago) could you show me the code and where to put it?
Thanks for your help
为什么不这样做你试着像我说的那样先写它。只是一个类中的静态方法,它接受一个double作为参数并返回一个布尔值。
Why don''t you try to write it first like I said. Just a static method in your class that takes a double as argument and returns a boolean.
这篇关于如何让程序做一些数学运算!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!