1. 轿车平均加速度 = 速度的变化量 / 时间的变化量
轿车用了8.7秒从0千米加速到每小时100千米
代码:
public class vp{
public static void main(String[] args){
int s0 = 0;//定义变量值
int s1 =(int)100.11;//浮点型强制转化成整型
int t0 = 0;
float t1 =8.7f;//单精度浮点型要加f
double v =(s1-s0)/(t1-t0);
System.out.println("这辆轿车的平均加速度为:"+v);
}
}
2. 克莱姆法则计算
解二元一次方程组 21.8x+2y=28和7x+8y=62组成方程组
代码:
//克莱姆法则
public class qj{
public static void main(String[] args){
double a = 21.8;//定义变量
// int b = 2 , e = 28 , c = 7 , d = 8 , f = 62;(中间用 顿号隔开 注意英文)
int b = 2;
int e = 28;
int c = 7;
int d = 8;
int f = 62;
/*double x1 = (e*d)-(b*f);
double x2 = (a*d)-(b*c);
double y1 = (a*f)-(e*c);
double y2 = (a*d)-(b*c);
*/
double x1 = (e*d - b*f) / (a*d - b*c); //运算符优先级是先乘除在加减
double y1 = (a*f - e*c) / (a*d - b*c);
System.out.println(x1);
System.out.println(y1);
/*double x = x1/x2;
double y = y1/y2;
System.out.println(x);
System.out.println(y);
*/
}}
x=0.62344
y=7.204488
标签:Java,int,double,编程,System,y1,println,out From: https://blog.csdn.net/2401_86416873/article/details/140621079