会出现的错误:
public class Homework{ public static void main(String[] args){ //1、错误:找不到符号 int xingming = 张三;//编译报错 //此处的张三可以理解为一个变量,该变量没有被声明 //修改代码,有很多方式 int 张三 = 125; int xingming = 张三; //2、错误:类型不兼容 //不兼容类型:String无法转换成int int xingming = "张三";//编译报错 //修改,前后类型一致 String xingming = "张三"; } }
习题:
1 public class Test1 { 2 public static void main(String[] args) { 3 //第一个学生信息 4 int number = 110; 5 System.out.println("学号"+number); 6 String name = "张三"; 7 System.out.println("姓名"+name); 8 char sex = '男'; 9 System.out.println("性别"+sex); 10 double height = 1.85; 11 System.out.println("身高"+height); 12 //第二个学生信息 13 int number1 = 120; 14 System.out.println("学号"+number1); 15 String name1 = "李四"; 16 System.out.println("姓名"+name1); 17 char sex1 = '女'; 18 System.out.println("性别"+sex1); 19 double height1 = 1.65; 20 System.out.println("身高"+height1); 21 } 22 }
运行结果: