编程:输入一个a,输出b的值.已知b与a的数学关系式"b等于32a分之15加2...
发布网友
发布时间:2024-09-29 03:34
我来回答
共1个回答
热心网友
时间:2024-11-05 05:45
1、输入的a是整数:
package test;
import java.util.Scanner;
public class aaaa {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入a:");
int a = s.nextInt();
double b = 0.0;
b = result(a,b);
System.out.println("结果b="+b);
}
private static double result(int a,double b) {
b = Math.round(15/(32*a))+21;
return b;
}
}
2、输入的a是小数或整数
package test;
import java.util.Scanner;
public class aaaa {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入a:");
double a = s.nextDouble();
double b = 0.0;
b = result(a,b);
System.out.println("结果b="+b);
}
private static double result(double a,double b) {
b = Math.round(15/(32*a))+21;
return b;
}
}