马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
学习视频:https://www.bilibili.com/video/BV17J411G72L?p=20
【1-19】
/*
练习1:打印个人信息
*/
//System.out.println()分行显示 System.out.print()一行显示
class TestExer1{
public static void main(String[] args) {
System.out.println("小明");
System.out.println(18);
System.out.println('女');
System.out.println(true);
System.out.println(40.2);
System.out.println("-------------------");
System.out.print("fdfd");
System.out.print('!');
}
}
//变量
class TestVariable{
public static void main(String[] args) {
int age = 10;
System.out.print(age);
}
}
class DefineAndUseVariable{
public static void main(String[] args) {
int age;
age = 18;
int age2 = 18;
System.out.println(age);
}
}
//int double String char boolean
class TestExer2{
public static void main(String[] args) {
String name = "dfd";
int age = 34;
char gender = '女';
double height = 152.2;
boolean marray = false;
System.out.println(name);
System.out.println("性别:" + gender);
System.out.println(height);
System.out.println(marray);
}
}
/*
基本数据类型
1.整型 byte(-128 127) short(-32768 32767) int long
2.小数 float double
3.字符 char
4.字符串 String
5.布尔 boolean
long需要加L 或 l float需要加f 或 F
*/
class TestType{
public static void main(String[] args) {
boolean marry = false;
if(marry) {
System.out.println("已婚");
}else {
System.out.println("未婚");
}
long time = 3223444444222L;
System.out.println(time);
float f = 34.35f;
System.out.println(f);
}
}
//字符常量可以用来表示转义字符'\n'(换行)'、'\t'(tab) '\b'(删除键)'\\' '"' '\r'(回车键)
//还可以表示'\u字符的unicode编值的十六位进制形式'
class TestExer3{
public static void main(String[] args) {
String bookName = "fdfd";
String author = "dfdf";
double price = 100.1;
int sale = 1;
int amout = 100;
boolean cu = false;
System.out.println("书名:" + bookName);
}
}
|