java1.52=的简单介绍
今天给各位分享java1.52=的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、用 Java 写一个两个整数相加的程序
- 2、javaSocket,大家帮我看下这个Socket错的那了么?为什么只能连1个连接?
- 3、我想问一下 java 中没有有Complex 这个变量,是需要自己定义吗?可是我看有些代码是直接用的。代码如下
- 4、java的BigDecimal类里的四舍五入方法怎么这么乱,到底5进位还是退位?
- 5、银行系统界面设计
用 Java 写一个两个整数相加的程序
代码如下:
public class Test {
public static int add(int a,int b){
return a+b;
}
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个数");
int a = scanner.nextInt();
System.out.println("请输入第二个数");
int b = scanner.nextInt();
System.out.println("和为:"+add(a,b));
}
}
扩展资料
运算符
运算符是一些特殊的符号,主要用于数学函数、一些类型的赋值语句和逻辑比较方面。
1、赋值运算符
赋值运算符以符号“=”表示,它是一个二元运算符(对两个操作数作处理),其功能是将右方操作数所含的值赋给左方的操作数。
例如:
1 int a = 100;
2、算术运算符
运算符说明 :
“+” 加 ;“-”\t减 ;“*”\t乘 ; “/”除 ; “%”\t取余数
3、自增和自减运算符
自增和自减是单目运算符,可以放在操作元之前,也可以放在操作元之后。操作元必须是一个整型或浮点型变量。自增、自减运算符的作用是使变量的值增1或减1。放在操作元前面的自增、自减运算符,会先将变量的值加1或减1,然后再使该变量参与表达式的运算。放在操作元后面的自增、自减运算符,会先使变量参与表达式的运算,然后再将该变量的值加1或减1。
例如:
假设a=5
1 b=++a;//先将a的值加1,然后赋值给b,此时a的值为6,b的值为6
2 b=a++;//先将a的值赋值给b,再将a的值变为6,此时a的值为6,b的值为5
4、比较运算符
比较运算符属于二元运算符,用于程序中的变量之间,变量和自变量之间以及其他类型的信息之间的比较。比较运算符的运算结果是boolean型。当运算符对应的关系成立时,运算的结果为true,否则为false。比较运算符共有6个,通常作为判断的依据用于条件语句中。
运算符说明:
""比较左方是否大于右方
"" 比较左方是否小于右方
"=="比较左方是否等于右方
" = "比较左方是否大于等于右方
"= "比较左方是否小于等于右方
"!= "比较左方是否不等于右方
参考链接:Java(计算机编程语言)_百度百科
javaSocket,大家帮我看下这个Socket错的那了么?为什么只能连1个连接?
是使用ServerSocket的类里的写法不正确
Rece类在accept了一个连接以后, 就进入了一个while循环, 去处理跟第一个连接的交互去了, 也就不会在回到accept上, 自然就连接不了第二个连接了.
服务端应该这样处理: accept一个连接之后, 启动一个新线程去专门和这个连接交互, 然后回到accept. 也就是说, 一个线程专门负责接受连接, 为每一个接受到的新连接创建一个新线程.
我想问一下 java 中没有有Complex 这个变量,是需要自己定义吗?可是我看有些代码是直接用的。代码如下
从你的问题描述看你是问是否有一个复数类型complex,我查了一下没有,都是自己定义的。下面的代码你可以参考:
/******************************************************************************
* Compilation: javac Complex.java
* Execution: java Complex
*
* Data type for complex numbers.
*
* The data type is "immutable" so once you create and initialize
* a Complex object, you cannot change it. The "final" keyword
* when declaring re and im enforces this rule, making it a
* compile-time error to change the .re or .im instance variables after
* they've been initialized.
*
* % java Complex
* a = 5.0 + 6.0i
* b = -3.0 + 4.0i
* Re(a) = 5.0
* Im(a) = 6.0
* b + a = 2.0 + 10.0i
* a - b = 8.0 + 2.0i
* a * b = -39.0 + 2.0i
* b * a = -39.0 + 2.0i
* a / b = 0.36 - 1.52i
* (a / b) * b = 5.0 + 6.0i
* conj(a) = 5.0 - 6.0i
* |a| = 7.810249675906654
* tan(a) = -6.685231390246571E-6 + 1.0000103108981198i
*
******************************************************************************/
import java.util.Objects;
public class Complex {
private final double re; // the real part
private final double im; // the imaginary part
// create a new object with the given real and imaginary parts
public Complex(double real, double imag) {
re = real;
im = imag;
}
// return a string representation of the invoking Complex object
public String toString() {
if (im == 0) return re + "";
if (re == 0) return im + "i";
if (im 0) return re + " - " + (-im) + "i";
return re + " + " + im + "i";
}
// return abs/modulus/magnitude
public double abs() {
return Math.hypot(re, im);
}
// return angle/phase/argument, normalized to be between -pi and pi
public double phase() {
return Math.atan2(im, re);
}
// return a new Complex object whose value is (this + b)
public Complex plus(Complex b) {
Complex a = this; // invoking object
double real = a.re + b.re;
double imag = a.im + b.im;
return new Complex(real, imag);
}
// return a new Complex object whose value is (this - b)
public Complex minus(Complex b) {
Complex a = this;
double real = a.re - b.re;
double imag = a.im - b.im;
return new Complex(real, imag);
}
// return a new Complex object whose value is (this * b)
public Complex times(Complex b) {
Complex a = this;
double real = a.re * b.re - a.im * b.im;
double imag = a.re * b.im + a.im * b.re;
return new Complex(real, imag);
}
// return a new object whose value is (this * alpha)
public Complex scale(double alpha) {
return new Complex(alpha * re, alpha * im);
}
// return a new Complex object whose value is the conjugate of this
public Complex conjugate() {
return new Complex(re, -im);
}
// return a new Complex object whose value is the reciprocal of this
public Complex reciprocal() {
double scale = re*re + im*im;
return new Complex(re / scale, -im / scale);
}
// return the real or imaginary part
public double re() { return re; }
public double im() { return im; }
// return a / b
public Complex divides(Complex b) {
Complex a = this;
return a.times(b.reciprocal());
}
// return a new Complex object whose value is the complex exponential of this
public Complex exp() {
return new Complex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
}
// return a new Complex object whose value is the complex sine of this
public Complex sin() {
return new Complex(Math.sin(re) * Math.cosh(im), Math.cos(re) * Math.sinh(im));
}
// return a new Complex object whose value is the complex cosine of this
public Complex cos() {
return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re) * Math.sinh(im));
}
// return a new Complex object whose value is the complex tangent of this
public Complex tan() {
return sin().divides(cos());
}
// a static version of plus
public static Complex plus(Complex a, Complex b) {
double real = a.re + b.re;
double imag = a.im + b.im;
Complex sum = new Complex(real, imag);
return sum;
}
// See Section 3.3.
public boolean equals(Object x) {
if (x == null) return false;
if (this.getClass() != x.getClass()) return false;
Complex that = (Complex) x;
return (this.re == that.re) (this.im == that.im);
}
// See Section 3.3.
public int hashCode() {
return Objects.hash(re, im);
}
// sample client for testing
public static void main(String[] args) {
Complex a = new Complex(5.0, 6.0);
Complex b = new Complex(-3.0, 4.0);
StdOut.println("a = " + a);
StdOut.println("b = " + b);
StdOut.println("Re(a) = " + a.re());
StdOut.println("Im(a) = " + a.im());
StdOut.println("b + a = " + b.plus(a));
StdOut.println("a - b = " + a.minus(b));
StdOut.println("a * b = " + a.times(b));
StdOut.println("b * a = " + b.times(a));
StdOut.println("a / b = " + a.divides(b));
StdOut.println("(a / b) * b = " + a.divides(b).times(b));
StdOut.println("conj(a) = " + a.conjugate());
StdOut.println("|a| = " + a.abs());
StdOut.println("tan(a) = " + a.tan());
}
}
java的BigDecimal类里的四舍五入方法怎么这么乱,到底5进位还是退位?
我来告诉你原因吧
up=四舍五入
down=五会舍去,大于5就入
然后你程序是错的
BigDecimal a = new BigDecimal(1.525);
BigDecimal b = new BigDecimal(-1.525);
System.out.println(a);
System.out.println(b);
new BigDecimal最好用string,你直接写数字的话,结果不是你想要的,以上程序,结果是:
1.524999999999999911182158029987476766109466552734375
-1.524999999999999911182158029987476766109466552734375
浮点数是不精确的
分给我吧
银行系统界面设计
用在银行系统界面,肯定不会用java或vb, 大部份都是用mainframe 或 as400, 他们的界面以简单快捷为主,不是按个键要等好几秒钟的那种!
其实好多mainframe / as400 都是用telnet session, 所以主要的控制在昼面跳画面之间的控制.主要用数字来跳画面或者是function key f1...f12.
java1.52=的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、java1.52=的信息别忘了在本站进行查找喔。