public class dog {
int weight;
public void eat()
{
System.out.println("謝謝主人");
weight++;
}
public void show()
{
System.out.println("我已經(jīng)"+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("有點(diǎn)開竅了刹前,編程挺有意思啊");
}
else {
System.out.println("我現(xiàn)在很牛逼了");
}
}
}
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++;
//生成一個隨機(jī)數(shù)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("有點(diǎn)開竅了懈凹,編程挺有意思啊");
}
else if(value>=50 && value < 100)
{
System.out.println("還是不行啊洁奈,知識太多了");
}
else
{
System.out.println("我現(xiàn)在很牛逼了");
}
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()
{
//生成一個隨機(jī)數(shù)組下標(biāo)[0-6)之間的數(shù)
int index = (int)(Math.random()*6);
return value[index];
}
//用來計(jì)數(shù)1-6之間的數(shù)一共出現(xiàn)了幾次的一個數(shù)組
int[] count = new int[7];
Dice dice = new Dice();//創(chuàng)建 一個骰子對象(6個面都是0)
dice.init();//初始化骰子對象画拾,把6個面都賦上值
//模擬拋600000次骰子
for(int i = 0; i < 60; i++)
{
int num = dice.throwDice();//本次骰子的點(diǎn)數(shù)(1-6)之間的數(shù)
//把點(diǎn)數(shù)作為下標(biāo)厚满,代入到count數(shù)組中,將count[num]對應(yīng)的值+1(記錄num出現(xiàn)的次數(shù))
// count[num]當(dāng)前的值托猩,保存著num已經(jīng)出現(xiàn)了多少次這個信息
count[num]++;
// System.out.println(num);
}
//最終對count數(shù)組遍歷印蓖,
for(int i = 1; i < count.length; i++)
{
//count[i]里保存著i出現(xiàn)了多少次
System.out.println(i+"出現(xiàn)了" +count[i]+"次");
}