算法与程序设计
的有关信息介绍如下:
1.public class TestRandomArray { public static void main(String[] args) { int maxline = (int) (Math.random()*100); int[] array = new int[maxline]; for(int i=0;i=10&&temp<=99) { array[i] = temp; } else i--; } for(int j=0;jmax) { max=array[j]; array[j] = array[0]; array[0] = max; } } for(int k=0;k= 3) && distance < 15) { money = money + 2*(distance-3); } if (distance > 15 ) { money = money + 2*12 + 3*(distance - 15); } return money; } public static void main(String args[]) { System.out.println("请输入公里数"); int distance_example=0; Scanner key = new Scanner(System.in); int n = key.nextInt(); distance_example = n; Caculate pay = new Caculate(); pay.money = pay.charge(distance_example); System.out.println("You need to pay money:"+pay.money+" distance is:"+distance_example); }} 5.public class Test4{public static void main (String args[]) { int n=100; while(n<=1000) { int i,j,k; i=n/100; j=(n-i*100)/10; k=n%10; if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n) System.out.print(n+String.valueOf('\t')); n++; } } }6.public class TestMoney{ public static void main(String[] args) { int one=1,two=2,five=5; for(int i=1;i<100;i++) for(int j=1;j<50;j++) for(int k=1;k<20;k++) { if((i*one+j*two+k*five)==100) System.out.println(i+"个一分,"+j+"个两分,"+k+"个五分"); } }}7.import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class TestJieCheng{ public static void main (String args[]) { int a=0,b=1;float sum=0; System.out.print("请输入要计算的阶乘:"); try { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); a=Integer.parseInt(in.readLine()); }catch(IOException e){} for(int i=1;i<=a;i++) { b=b*i; } System.out.print(a+"的阶乘是"+b); }}7.public class XXX{ public static void main() { for(int i=1 i<=10;i++) { int j,sum; j=math(i); sum+=j; } int math(int i){ int k=i; int b=1; for(int w=1;w<=k;w++) { b=b*w; } return b; } } } 8.public class Test4{public static void main (String args[]) { int n=100; while(n<=1000) { int i,j,k; i=n/100; j=(n-i*100)/10; k=n%10; if((Math.pow(i, 3)+Math.pow(j, 3)+Math.pow(k, 3))==n) System.out.print(n+String.valueOf('\t')); n++; } } }9.public class TestNumber2 { public static void main(String[] args) { final int maxline = 20; double sum = 0; double [] denominator = new double [maxline]; double [] numerator = new double [maxline]; for(int i=2;i
相关文章
-
2024-11-18 19:13
阅读(581)
-
2024-11-11 23:12
阅读(553)