实训一:Java入门 - Java初体验
第一关:Java第一课
public class HelloWorld{
public static void main(Stirng[] args){
System.out.println("姓名:张三");
System.out.println("年龄:25");
System.out.println("职业:JAVA高级工程师");
System.out.println("薪资:15K");
}
}
实训二:java入门-变量与数据类型
第一关:变量有常量
public class Helloworld{
public static void mian(String[] args){
String love="www.educoder.net";
System.out.println(love);
}
}
第二关:变量的使用
package chapter2;
public class HelloVariable {
public static void main(String[] args){
String love="我喜欢在educoder上学习";
System.out.println("变量love的值为"+love);
String userName="张无忌";
userName="李四";
System.out.println("重新赋值后变量userName的值为"+userName);
}
}
第四关:Java数据类型
package chapter2;
public class JavaDataType1 {
public static void main(String[] args) {
/********* Begin *********/
//在本行定义字符串变量name
String name="张无忌";
//在本行定义年龄变量 age
int age=23;
//在本行定义性别变量 sex
char sex='男';
//在本行定义分数变量 score
float score=66.6f;
/********* End *********/
System.out.println(name + age + "岁" + "性别:" + sex + "这次考了" + score + "分");
}
}
第五关:Java类型转换
package chapter2;
public class TypeConvert {
public static void main(String[] args) {
/********* Begin *********/
double score=89.3;
int scoreInt=(int)score;
System.out.println(score);
System.out.println(scoreInt);
/********* End *********/
}
}
第七关:Scanner的使用
package chapter2.step7;
/********* Begin *********/
import java.util.Scanner;
public class HelloWorld{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("请录入嫦娥个人信息:");
System.out.println("请输入姓名:");
String name = input.next();
System.out.println("请输入年龄:");
int age = input.nextInt();
System.out.println("请输入性别:");
String i = input.next();
System.out.println("请输入体重:");
double t = input.nextDouble();
System.out.println("请输入地址:");
String d = input.next();
System.out.println("请输入是否已婚:");
String y = input.next();
System.out.println("信息如下:");
System.out.println("\t"+"姓名:"+name);
System.out.println("\t"+"年龄:"+age+"岁");
System.out.println("\t"+"性别:"+i);
System.out.println("\t"+"体重:"+t+"kg");
System.out.println("\t"+"地址:"+d);
System.out.println("\t"+"婚否:"+y);
/********* End *********/
}
}
实训三:运算符和表达式
第一关:算术运算符:
package step1;
import java.util.Scanner;
public class Cal {
public static void main(String[] args) {
/*********start*********/
System.out.println("请输入第一个整数");
Scanner number=new Scanner(System.in);
int number1=number.nextInt();
System.out.println("请输入第二个整数");
int number2=number.nextInt();
System.out.println("两数相加的结果为:"+(number1+number2));
System.out.println("两数相减的结果为:"+(number1-number2));
System.out.println("两数相乘的结果为:"+(number1*number2));
System.out.println("两数相除的结果为:"+(number1/number2));
System.out.println("两数取余数的结果为:"+(number1%number2));
/*********end*********/
}
}
第二关:关系运算符
package step2;
import java.util.Scanner;
public class Relative {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
/*********start*********/
System.out.println("a==b="+(a==b));
System.out.println("a!=b="+(a!=b));
System.out.println("a>b="+(a>b));
System.out.println("a<b="+(a<b));
System.out.println("b>=a="+(b>=a));
System.out.println("b<=a="+(b<=a));
/*********end*********/
}
}
第三关:逻辑运算符
package step3;
import java.util.Scanner;
public class testLogic {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
boolean a=sc.nextBoolean();
boolean b=sc.nextBoolean();
boolean c=sc.nextBoolean();
/*********start *********/
System.out.println(!a);
System.out.println(a==b);
System.out.println(a==c);
System.out.println(!b);
/*********end *********/
}
}
第四关:三元运算符
package step4;
import java.util.Scanner;
public class TestYear {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int year=sc.nextInt();
boolean result;
/********start********/
result=(year%400==0)?true:false;
result=(year%4==0)&&(year%100!=0)?true:false;
System.out.println(year + "年是否为闰年:" + result);
/********end********/
}
}
第五关:运算符的优先级
package step5;
import java.util.Scanner;
public class TestDemo5 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("输入:");
int m=sc.nextInt();
int n=sc.nextInt();
System.out.println("输出:");
/*****start*****/
System.out.println( (m+n)*2 );
System.out.println( (m-n)%3 );
System.out.println((m-n)/2 + (m+n)*2);
/*****end*****/
}
}