java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-21

来源:互联网 发布:微信怎么分享淘宝店铺 编辑:程序博客网 时间:2024/05/02 05:09
package chapter7;public class T21 {public static void main(String[] args) {int boll = 5;int slot = 8;int[] b = new int[boll];for(int i=0;i<boll;i++){b[i]=1;for(int j=0;j<slot;j++){int random = r();b[i]+=random;if(random==0)System.out.print("L");elseSystem.out.print("R");}System.out.println();}System.out.println();for(int e:b){System.out.print(e+" ");}System.out.println();for(int i=0;i<boll;i++){for(int j=0;j<b[i];j++)System.out.print(" ");System.out.println("0");}}public static int r(){return (int)(Math.random()*2);}}

0 0
原创粉丝点击