概述
大学本科在实验室收集完密立根油滴实验后懒得用计算器挨个算结果,写了个计算代码偷个懒(Doge)
package xxx;
import java.util.Scanner;
public class xxx {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double[] U = new double[6], t = new double[6], q = new double[6], e = new double[6];
double sum1, sum2 = 0, avg1, avg2, n;
int count1, count2 = 0;
System.out.println("nSet U to 0 if data is invalid!");
for (int num = 1; num <= 5; num++) {
sum1 = count1 = 0;
for (int i = 0; i < 6; i++) {
System.out.print("U" + (i + 1) + " = ");
U[i] = sc.nextDouble();
}
for (int i = 0; i < 6; i++) {
System.out.print("t" + (i + 1) + " = ");
t[i] = sc.nextDouble();
}
for (int i = 0; i < 6; i++) {
if (U[i] != 0) {
q[i] = (1.43E-14) / (Math.pow((t[i] * (1 + 0.02 * Math.sqrt(t[i]))), 1.5) * U[i]);
System.out.println("q" + (i + 1) + " = " + q[i]);
sum1 += q[i];
} else {
System.out.println("q" + (i + 1) + " = No data");
count1++;
}
}
avg1 = sum1 / (6 - count1);
n = avg1 / 1.60E-19;
System.out.println("nq(avg) = " + avg1);
System.out.println("n = " + n + "n");
System.out.print("Continue? (0/1):");
if (sc.nextInt() == 1) {
System.out.print("Enter n:");
n = sc.nextInt();
e[num - 1] = avg1 / n;
System.out.println("e" + num + " = " + e[num - 1] + "n");
sum2 += e[num - 1];
} else {
System.out.println("e" + num + " = No datan");
count2++;
}
}
avg2 = sum2 / (5 - count2);
System.out.print("e(avg) = " + avg2);
}
}
测试结果如下:
Set U to 0 if data is invalid!
U1 = 234
U2 = 235
U3 = 235
U4 = 235
U5 = 235
U6 = 236
t1 = 11.5
t2 = 11.0
t3 = 11.1
t4 = 11.3
t5 = 11.3
t6 = 10.7
q1 = 1.4201176665620323E-18
q2 = 1.5147472791392711E-18
q3 = 1.493691757850903E-18
q4 = 1.4529909046573857E-18
q5 = 1.4529909046573857E-18
q6 = 1.5742222827528064E-18
q(avg) = 1.4847934659366305E-18
n = 9.27995916210394
Continue? (0/1):1
Enter n:9
e1 = 1.6497705177073672E-19
U1 = 255
U2 = 255
U3 = 255
U4 = 255
U5 = 255
U6 = 255
t1 = 21.5
t2 = 22.3
t3 = 20.4
t4 = 21.7
t5 = 21.7
t6 = 22.0
q1 = 4.924534453987032E-19
q2 = 4.65100924528919E-19
q3 = 5.345791784532137E-19
q4 = 4.853742967556858E-19
q5 = 4.853742967556858E-19
q6 = 4.750616851159173E-19
q(avg) = 4.896573045013541E-19
n = 3.0603581531334636
Continue? (0/1):1
Enter n:3
e2 = 1.6321910150045138E-19
U1 = 292
U2 = 293
U3 = 293
U4 = 294
U5 = 294
U6 = 294
t1 = 12.3
t2 = 12.1
t3 = 12.0
t4 = 11.9
t5 = 11.8
t6 = 11.8
q1 = 1.025493641332223E-18
q2 = 1.0482780109194546E-18
q3 = 1.0618377086621327E-18
q4 = 1.0720279866013955E-18
q5 = 1.0861269919892745E-18
q6 = 1.0861269919892745E-18
q(avg) = 1.0633152219156258E-18
n = 6.6457201369726615
Continue? (0/1):0
e3 = No data
U1 = 214
U2 = 0
U3 = 214
U4 = 214
U5 = 213
U6 = 214
t1 = 19.6
t2 = 0
t3 = 19.5
t4 = 20.5
t5 = 20.4
t6 = 20.0
q1 = 6.780618489349224E-19
q2 = No data
q3 = 6.834973940577324E-19
q4 = 6.321509555880487E-19
q5 = 6.399891573031432E-19
q6 = 6.570080177250559E-19
q(avg) = 6.581414747217805E-19
n = 4.113384217011128
Continue? (0/1):1
Enter n:4
e4 = 1.6453536868044512E-19
U1 = 200
U2 = 200
U3 = 201
U4 = 201
U5 = 201
U6 = 201
t1 = 11.3
t2 = 11.5
t3 = 11.3
t4 = 11.3
t5 = 11.3
t6 = 11.4
q1 = 1.707264312972428E-18
q2 = 1.6615376698775779E-18
q3 = 1.6987704606690825E-18
q4 = 1.6987704606690825E-18
q5 = 1.6987704606690825E-18
q6 = 1.6757681420705085E-18
q(avg) = 1.6901469178212937E-18
n = 10.563418236383086
Continue? (0/1):0
e5 = No data
e(avg) = 1.642438406505444E-19
进程已结束,退出代码为 0
最后
以上就是缓慢棒棒糖为你收集整理的【大学物理】密立根油滴实验数据计算代码的全部内容,希望文章能够帮你解决【大学物理】密立根油滴实验数据计算代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复