import java.util.Scanner; public class Prog15{ public static void main(String[] args){ Scanner scan = new Scanner(System.in).useDelimiter("\\D"); System.out.print("请输入三个数:"); int x = scan.nextInt(); int y = scan.nextInt(); int z = scan.nextInt(); scan.close(); System.out.println("排序结果:"+sort(x,y,z)); } //比较两个数的大小 private static String sort(int x,int y,int z){ String s = null; if(x>y){ int t = x; x = y; y = t; } if(x>z){ int t = x; x = z; z = t; } if(y>z){ int t = z; z = y; y = t; } s = x+" "+y+" "+z; return s; } } |
public class Prog16{ public static void main(String[] args){ for(int i=1;i<10;i++){ for(int j=1;j<i+1;j++) System.out.print(j+"*"+i+"="+(j*i)+" "); System.out.println(); } } } |
public class Prog17{ public static void main(String[] args){ int m = 1; for(int i=10;i>0;i--) m = 2*m + 2; System.out.println("小猴子共摘了"+m+"桃子"); } } |
import java.util.ArrayList; public class Prog18{ String a,b,c;//甲队成员 public static void main(String[] args){ String[] racer = {"x","y","z"};//乙队成员 ArrayList<Prog18> arrayList = new ArrayList<Prog18>(); for(int i=0;i<3;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++){ Prog18 prog18 = new Prog18(racer,racer[j],racer[k]); if(!prog18.a.equals(prog18.b) && !prog18.a.equals(prog18.c) && !prog18.b.equals(prog18.c) && !prog18.a.equals("x") && !prog18.c.equals("x") && !prog18.c.equals("z")) arrayList.add(prog18); } for(Object obj:arrayList) System.out.println(obj); } //构造方法 private Prog18(String a,String b,String c){ this.a = a; this.b = b ; this.c = c; } public String toString(){ return "a的对手是"+a+" "+"b的对手是"+b+" "+"c的对手是"+c; } } |
public class Prog19{ public static void main(String[] args){ int n = 5; printStar(n); } //打印星星 private static void printStar(int n){ //打印上半部分 for(int i=0;i<n;i++){ for(int j=0;j<2*n;j++){ if(j<n-i) System.out.print(" "); if(j>=n-i && j<=n+i) System.out.print("*"); } System.out.println(); } //打印下半部分 for(int i=1;i<n;i++){ System.out.print(" "); for(int j=0;j<2*n-i;j++){ if(j<i) System.out.print(" "); if(j>=i && j<2*n-i-1) System.out.print("*"); } System.out.println(); } } } |
public class Prog20{ public static void main(String[] args){ double n1 = 1; double n2 = 1; double fraction = n1/n2; double Sn = 0; for(int i=0;i<20;i++){ double t1 = n1; double t2 = n2; n1 = t1+t2; n2 = t1; fraction = n1/n2; Sn += fraction; } System.out.print(Sn); } } |
Miss.H 发表于 2015-7-7 23:29
感谢分享不错学到很多,但是我们这是学Java不是算法啊
Miss.H 发表于 2015-7-7 23:29
感谢分享不错学到很多,但是我们这是学Java不是算法啊
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |