public class dog {
int weight;
public void eat()
{
System.out.println("谢谢主人");
weight++;
}
public void show()
{
System.out.println("我已经"+weight+"斤重了");
}
}
dog s1 =new dog();
s1.weight=1;
for (int i = 0;i<20;i++)
{
s1.show();
s1.eat();
}
public class student {
int jingyian;
public void xuexi()
{
jingyian++;
System.out.println(jingyian);
}
public void show()
{
if (jingyian<10){
System.out.println("编程太难了,还是头疼啊");
}
else if (jingyian<50){
System.out.println("有点开窍了,编程挺有意思啊");
}
else {
System.out.println("我现在很牛逼了");
}
}
}
student zhu = new student();
Scanner scanner = new Scanner(System.in);
System.out.println("输入");
int jingyanzhi=scanner.nextInt();
for (int i = 0;i<jingyanzhi;i++)
{
zhu.xuexi();
}
zhu.show();
int value;
int age;
String name;
public String getName()
{
name = "zhangsan";
return name;
}
public int getAge()
{
System.out.println("我的名字是" + getName());
return age;
}
public void study()
{
value++;
//生成一个随机数0-365
int day = (int)(Math.random()*365);
if(day == 66)//
{
age++;
}
}
public void show()
{
if(value<10)
{
System.out.println("编程太难了,还是头疼啊");
}
else if(value>=10 && value < 50)
{
System.out.println("有点开窍了,编程挺有意思啊");
}
else if(value>=50 && value < 100)
{
System.out.println("还是不行啊,知识太多了");
}
else
{
System.out.println("我现在很牛逼了");
}
Student s1 = new Student();
for(int i = 0; i < 36500; i++)
{
s1.study();
}
s1.show();
int age = s1.getAge();
System.out.println(age);
String sName = s1.getName();
System.out.println(sName);
啊啊啊啊啊啊
int[] value = new int[6];
//初始化
public void init()
{
for(int i = 0; i < 6; i++)
{
value[i] = i+1;
}
}
//抛骰子
public int throwDice()
{
//生成一个随机数组下标[0-6)之间的数
int index = (int)(Math.random()*6);
return value[index];
}
//用来计数1-6之间的数一共出现了几次的一个数组
int[] count = new int[7];
Dice dice = new Dice();//创建 一个骰子对象(6个面都是0)
dice.init();//初始化骰子对象,把6个面都赋上值
//模拟抛600000次骰子
for(int i = 0; i < 60; i++)
{
int num = dice.throwDice();//本次骰子的点数(1-6)之间的数
//把点数作为下标,代入到count数组中,将count[num]对应的值+1(记录num出现的次数)
// count[num]当前的值,保存着num已经出现了多少次这个信息
count[num]++;
// System.out.println(num);
}
//最终对count数组遍历,
for(int i = 1; i < count.length; i++)
{
//count[i]里保存着i出现了多少次
System.out.println(i+"出现了" +count[i]+"次");
}
网友评论