packageexample;publicclassDemo1{publicstaticvoidmain(String[] args){int r =3;double PI =3.14;double v =(4.0*Math.PI * r)/3.0;System.out.println("圆球体积:"+ v);}}
packageexample;publicclassDemo3{publicstaticvoidmain(String[] args){System.out.println("水仙花数有:");for(int i =0; i <1000; i++){int h = i /100;int t = i %100/10;int s = i %10;if(h * h * h + t * t * t + s * s * s == i){System.out.print(i +" ");}}}}
packageexample;publicclassDemo7{publicstaticvoidisPrime(int n){int m =0;for(int i =2; i < n; i++){if(n % i ==0)
m++;}if(m ==0){System.out.println(n);}}publicstaticvoidmain(String args[]){for(int i =100; i <=200; i++){isPrime(i);}}}
(八)编写程序,求出一个计算3×3矩阵的两条对角线(主、辅对角线)上的元素之和。
packageexample;importjava.util.Scanner;publicclassDemo8{publicstaticvoidmain(String[] args){System.out.println("请输入九个整数:");Scanner sc =newScanner(System.in);int[][] a =newint[3][3];for(int i =0; i <3; i++){for(int j =0; j <3; j++){
a[i][j]= sc.nextInt();}}int sum1 =0, sum2 =0;for(int i =0; i <3; i++){for(int j =0; j <3; j++){if(i == j){
sum1 += a[i][j];}if(i + j ==2){
sum2 += a[i][j];}}}System.out.println("主对角线元素之和为:"+ sum1);System.out.println("辅对角线元素之和为:"+ sum2);
sc.close();}}
(一)已知圆球体积公式为V=4/3·pi·r3,是编写程序设计一个求圆球体积的方法,并在主程序中调用它,求出当r=3时圆球的体积值。package example;public class Demo1 { public static void main(String[] args) { int r = 3; double PI = 3.14; double v = (4.0 * Math.PI * r) / 3.0; Syst.