九九乘法表
package nlday01;
public class nnmulti {
public static void main(String[] args) {
for(int i=1;i<10;i++){
for(int j=1;j<i+1;j++){
System.out.print(i+"*"+j+"="+i*j+"\t");
}
System.out.println();
}
}
}
运行结果如下我做过两次这题,但都只是看一眼,都被整体换行难住了, System.out.println();以及两个for的搭配。(如果有大佬看见我的代码,不要见笑~)
根据月份判断季节
package nlday01;
public class season {
public static void main(String[] args) {
boolean flag = true;
while(flag){
System.out.println("Please input your month:(press 0 to stop p)");
Scanner scan = new Scanner(System.in);
int month = scan.nextInt();
switch(month){
case 12:
case 1:
case 2: System.out.println("winter");break;
case 3:
case 4:
case 5: System.out.println("spring");break;
case 6:
case 7:
case 8: System.out.println("summer");break;
case 9:
case 10:
case 11: System.out.println("fall");break;
case 0:flag = false;break;
default: System.out.println("error");break;
}
}
}
}
这个代码,我一开始竟然很蠢的写了12行System.out.println();后来才发现有些看可以不用加break。。。还有,文中有波浪线或者错误的,我当时也不知道要添加头文件。
运行结果如下:
Java中的数组
老师主要讲了数组的定义
类和对象
package nlday01;
public class Person {
private String name;//define les shuxing
private int age;
private char sex;
//定义类的方法
public void eat(){
System.out.println("feed my belly");
}
public void sleep(String where){
System.out.println("i am at" + where + "sleep");
}
public int study(){
int count = (int)(Math.random()*10);
System.out.println("i love study" + count + "kinds subjects");
return count;
}
public static void main(String[] args){
Person person = new Person();
person.name = "HuiZhen.Yu";
person.age = 20;
person.sex = '女';
person.eat();
person.sleep("yifulou");
person.study();
}
}
运行结果如下:
这里老师开车很快,用苍老师和石老师给我们当例子,哈哈哈。
五次机会猜数
老师要来关门了,我先回宿舍,明早来补充这个代码。顺便明天把day02和day03的补上,尽量明天把day04的也加上。