第五天:
public class ArgsDemo {
public static void main(String[] args) {
// 定义变量
int a = 10;
int b = 20;
System.out.println("a:" + a + ",b:" + b);// a:10,b:20
change(a, b);
System.out.println("a:" + a + ",b:" + b);// a:10,b:20
}
public static void change(int a, int b) { // a=10,b=20
System.out.println("a:" + a + ",b:" + b);// a:10,b:20
a = b; // a=20;
b = a + b;// b=40;
System.out.println("a:" + a + ",b:" + b);// a:20,b:40
}
}
第六天:
package com.itheima;
/*
* 需求:打印5位数中的所有回文数。
* 什么是回文数呢?举例:12321是回文数,个位与万位相同,十位与千位相同。
*
* 分析:
* A:5位数告诉了我们数据的范围,用for循环实现
* B:获取每一个5位数,然后得到它的个位,十位,千位,万位
* 假设x是一个5位数:
* 个位:x%10
* 十位:x/10%10
* 千位:x/10/10/10%10
* 万位:x/10/10/10/10%10
* C:把满足条件的数据输出即可
*/
public class Test3 {
public static void main(String[] args) {
//5位数告诉了我们数据的范围,用for循环实现
for(int x=10000; x<100000; x++) {
//获取每一个5位数,然后得到它的个位,十位,千位,万位
int ge = x%10;
int shi = x/10%10;
int qian = x/10/10/10%10;
int wan = x/10/10/10/10%10;
public class StudentDemo {
public static void main(String[] args) {
//如何调用构造方法呢?
//通过new关键字调用
//格式:类名 对象名 = new 构造方法(...);
Student s = new Student();
}
}
第八天:
3.3.1.1案例代码十五:
package com.itheima_03;
/*
* StringBuilder和String的相互转换
*
* StringBuilder -- String
* public String toString():通过toString()就可以实现把StringBuilder转成String
*
* String -- StringBuilder
* StringBuilder(String str):通过构造方法就可以实现把String转成StringBuilder
*/
public class StringBuilderTest {
public static void main(String[] args) {
//StringBuilder -- String
/*
StringBuilder sb = new StringBuilder();
sb.append("hello").append("world");
String s = sb.toString();
System.out.println(s);
*/
//String -- StringBuilder
String s = "helloworld";
StringBuilder sb = new StringBuilder(s);
System.out.println(sb);
}
}
第九天:
package com.itheima;
/*
* 创建一个学生数组,存储三个学生对象并遍历
*
* 分析:
* A:定义学生类
* B:创建学生数组
* C:创建学生对象
* D:把学生对象作为元素赋值给学生数组
* E:遍历学生数组
*/
public class StudentDemo {
public static void main(String[] args) {
//创建学生数组
Student[] students = new Student[3];
//创建学生对象
Student s1 = new Student("曹操",40);
Student s2 = new Student("刘备",35);
Student s3 = new Student("孙权",30);