1011
题目描述
输入圆柱体的底面半径r和高h,计算圆柱体的表面积并输出到屏幕上。要求定义圆周率为如下宏常量
#define PI 3.14159
输入
输入两个实数,为圆柱体的底面半径r和高h。
输出
输出一个实数,即圆柱体的表面积,保留2位小数。
样例输入
42.1 71.6
样例输出
30076.14
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double r = sc.nextDouble();
double h = sc.nextDouble();
double PI = 3.14159;
double l = 2 * PI * r;
double s1 = PI * r * r;
double s = 2 * s1 + h * l;
System.out.printf("%.2f", s);
}
}
1012
题目描述
求实数的绝对值。
输入
输入一个实数。
输出
输出它的绝对值,结果保留两位小数
样例输入
-234.00
样例输出
234.00
提示
关于数学函数,在课程网站上有专题讲解,第二章的边讲边写:数学函数
https://www.icourse163.org/learn/ZZULI-1206704833?tid=1465320443#/learn/content?type=detail&id=1245348005&cid=1270255017
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double b = Math.abs(a);
System.out.printf("%.2f", b);
}
}
1013
题目描述
给定A(x1, y1), B(x2, y2)两点坐标,计算它们间的距离。
输入
输入包含四个实数x1, y1, x2, y2,分别用空格隔开,含义如描述。其中0≤x1,x2,y1,y2≤100。
输出
输出占一行,包含一个实数d,表示A, B两点间的距离。结果保留两位小数。
样例输入
1 1.5 2 2.5
样例输出
1.41
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double a = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
double b = Math.sqrt(a);
System.out.printf("%.2f", b);
}
}
1014
题目描述
给出三角形的三条边,求三角形的面积。
输入
输入三角形的三条边长(实数),数据之间用空格隔开。
输出
输出三角形的面积,结果保留2位小数。
样例输入
2.5 4 5
样例输出
4.95
提示
用海伦公式或其他方法均可。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
double p = (a + b + c) / 2;
double s = Math.sqrt(p * (p - a) * (p - b) * (p - c));
System.out.printf("%.2f", s);
}
}
1015
题目描述
读入两个用“时:分:秒”表示的时间点,计算以秒为单位的时间间隔。
输入
输入有两行,每行是一个用“时:分:秒”表示的时间点。测试数据保证第二个时间点晚于第一个时间点。
输出
输出一个整数,表示时间间隔的秒数。
样例输入
08:00:00 09:00:00
样例输出
3600
提示
输入数据中带有普通字符,如冒号,scanf函数的格式字符串中对应位置上也要有对应字符。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//输入两个字符串
String s1 = sc.nextLine();
String s2 = sc.nextLine();
//把字符串s1,s2中的数字筛选出来放入数组arr1,arr2
String[] arr1 = s1.split(":");
String[] arr2 = s2.split(":");
//把arr1,arr2转换成int类型的数组arr3,arr4
int[] arr3 = new int[arr1.length];
int[] arr4 = new int[arr2.length];
for (int i = 0; i < arr1.length; i++) {
arr3[i] = Integer.parseInt(arr1[i]);
}
for (int i = 0; i < arr1.length; i++) {
arr4[i] = Integer.parseInt(arr2[i]);
}
//计算时间
int t1 = 0, t2 = 0;//定义两个变量存放时间
for (int i = 0; i < arr3.length; i++) {
if (i == 0) {
t1 += arr3[i] * 3600;
} else if (i == 1) {
t1 += arr3[i] * 60;
} else {
t1 += arr3[i];
}
}
for (int i = 0; i < arr4.length; i++) {
if (i == 0) {
t2 += arr4[i] * 3600;
} else if (i == 1) {
t2 += arr4[i] * 60;
} else {
t2 += arr4[i];
}
}
System.out.println(t2 - t1);
}
}