Cirry's Blog

类之间的相互继承

Oct 12, 2019
技术 java
1分钟
199字

StringBuffer

public class Demo {
public static void main(String[] args) {
StringBuffer buf = new StringBuffer();
for(int x = 'a'; x <'z'; x ++){
buf.append((char) x);
}
buf.reverse().delete(0, 5);
System.out.println(buf);
}
}

随机数组

package cn.cccc.demo;
import java.util.Arrays;
import java.util.Random;
class NumberFactory{
private static Random random = new Random();
public static int [] create(int len ){
int data [] = new int [len];
int foot = 0;
while(foot < data.length){
int num = random.nextInt(30);
data[foot++] = num;
}
return data;
}
7 collapsed lines
}
public class Demo {
public static void main(String[] args) {
int result [] = NumberFactory.create(5);
System.out.println(Arrays.toString(result));
}
}

抛硬币检测

package cn.cccc.demo;
import java.util.Arrays;
import java.util.Random;
class Coin {
private static Random random = new Random();
private int front;
private int back;
public void throwCoin(int count){
for(int x= 0; x < count ; x++){
int side = random.nextInt(2);
if(side == 0 ){
this.front++;
}else {
this.back++;
}
16 collapsed lines
}
}
public int getFront(){
return this.front;
}
public int getBack(){
return this.back;
}
}
public class Demo {
public static void main(String[] args) {
Coin coin = new Coin();
coin.throwCoin(1000);
System.out.println("正面的次数"+coin.getFront()+",背面的次数"+coin.getBack());
}
}
本文标题:类之间的相互继承
文章作者:Cirry
发布时间:Oct 12, 2019
感谢大佬送来的咖啡☕
alipayQRCode
wechatQRCode
总访问量
总访客数人次