暑假学习第三天
作者:互联网
面向对象:类 对象
package com.yang.www.base.objectproject;
public class Dog {
String name;
int age;
float weight;
public static void main(String[] args) {
Dog duoduo = new Dog();
duoduo.name = "多多";
duoduo.age = 6;
duoduo.weight = 13.5f;
Dog lucky = new Dog();
lucky.name = "lucky";
lucky.age = 3;
lucky.weight = 12.2f;
System.out.println(duoduo.name+"今天"+duoduo.age+"岁了");
System.out.println(lucky.name+"体重"+lucky.weight+"kg");
}
}
Method
package com.yang.www.base.objectproject;
public class Method01 {
public String isOddNumber(int num){
System.out.println("原始数字为:" + num);
if (num % 2 == 0){
return "偶数";
}
else{
return "奇数";
}
}
public static void main(String[] args) {
int a = 10;
Method01 method01 = new Method01();
String r1 = method01.isOddNumber(a);
System.out.println(a + "是" + r1);
int b = 5;
String r2 = method01.isOddNumber(b);
System.out.println(b + "是" + r2);
}
}
三元运算符:x ? y : z
如果x==true 则结果为y 否则结为z
包机制
倒置域名为包名
引用包为import
标签:System,String,第三天,duoduo,lucky,学习,暑假,public,out 来源: https://www.cnblogs.com/lyy-599/p/16434975.html