类,对象,控制台输入输出
规范:一个项目应该只有一个main方法
一个类里面只有属性和方法。
关键字:this
this.name:表示当前这个类的name。当前
查询是否为闰年
Scanner scanner = new Scanner(System.in);
System.out.println( scanner.hasNext()); //运行上面的程序,控制台等待键盘输入,输入信息后输出结果为true。
import java.util.Scanner;//导入Scanner类到程序中
public class test002 {
public static void main(String[] args) {
//控制台输入输出
Scanner name = new Scanner(System.in);//创建name对象
System.out.print("请输入你的姓名:");
String name01 =name.next();//获取输入的数据,放到name中
System.out.println("你的姓名是:"+name01);//打印输出
}
}
查询月份
package bao;
import java.util.Scanner;
public class month {
public static void main(String[] args) {
Scanner month_1 = new Scanner(System.in);
System.out.print("请输入需要查询的月份 :");
int month_2 = month_1.nextInt();
if (1<=month_2&&month_2<=12) {
if (month_2 == 1 || month_2 == 3 || month_2 == 5 || month_2 == 7 || month_2 == 8 || month_2 == 10 || month_2 == 12) {
System.out.print("您查询的月份为:31天");
}
if (month_2 == 4 || month_2 == 6 || month_2 == 9 || month_2 == 11) {
System.out.print("您查询的月份为:30天");
}
if (month_2 == 2) {
System.out.print("2月是平月(二十八天)或者是闰月(二十九天),具体看是平年还是闰年!");
}
}
else
System.out.println("好家伙,你填月份等会填错。不愧是你!");
}
}
加减乘除
package bao;
import java.util.Scanner;
public class count {
public static void main(String[] args) {
System.out.print("大兄弟,请输入需要计算的第一个数字 :");
Scanner one = new Scanner(System.in);
float one_1=one.nextFloat();
System.out.print("第二个数字");
Scanner two = new Scanner(System.in);
float two_1=two.nextFloat();
double c=0;
System.out.println(one_1 + two_1);
System.out.println(one_1 - two_1);
System.out.println(one_1 * two_1);
c=(double)(Math.round(one_1/two_1));
System.out.println(c);
}
}
判断输入的字符为什么
package bao;
import java.util.Scanner;
public class judga {
public static void main(String[] args) {
Scanner judga1 = new Scanner(System.in);
System.out.print("请输入需要识别的字符 :");
char judga2 = judga1.next().charAt(0);
if (judga2 >= 0 && judga2 <= 9) {
System.out.print("数字");
} if (judga2 >= 'a'&& judga2 <= 'z') {
System.out.print("小写字母");
} if (judga2 >= 'A' && judga2 <= 'Z') {
System.out.print("大写字母");
}
else {
System.out.print("其他字符");
}
}
}
垃圾牌万年历
package bao;
import java.util.Scanner;
public class zip {
public static void main(String[] args) {
System.out.println(" 欢迎来到万年历APP系统! ");
System.out.print("请输入需要查询的年份 :");
Scanner year = new Scanner(System.in);
int year1 = year.nextInt();
if (((year1 % 4 == 0) && (year1 % 100 != 0)) || (year1 % 400 == 0)) {
System.out.println("你输入的 " + year1 + "为闰年");
} else
System.out.println("你输入的是平年");
System.out.print("请输入需要查询的月份 :");
Scanner month = new Scanner(System.in);
int month1 = month.nextInt();
if (month1 == 1) {
System.out.println("星期一 星期二 星期三 星期四 星期五 星期六 星期天");
System.out.println(" 1 2 3 4 5 6 7");
System.out.println(" 5 6 7 8 9 10 11");
System.out.println(" 12 13 14 15 16 17 18");
System.out.println(" 19 20 21 22 23 24 25");
System.out.println(" 26 27 28 29 30 31 ");
}
else if (month1 == 2) {
System.out.println("星期一 星期二 星期三 星期四 星期五 星期六 星期天");
System.out.println(" 1 2 3 4 5 6 7");
System.out.println(" 5 6 7 8 9 10 11");
System.out.println(" 12 13 14 15 16 17 18");
System.out.println(" 19 20 21 22 23 24 25");
System.out.println(" 26 27 28 29 ");
System.out.println("2月是平月(二十八天)或者是闰月(二十九天),具体看是平年还是闰年!");
System.out.println("此处日历以润年为例!");
}
else if (month1==3) {
System.out.println("星期一 星期二 星期三 星期四 星期五 星期六 星期天");
System.out.println(" 1 2 3 4 5 6 7");
System.out.println(" 5 6 7 8 9 10 11");
System.out.println(" 12 13 14 15 16 17 18");
System.out.println(" 19 20 21 22 23 24 25");
System.out.println(" 26 27 28 29 30 31 ");
}
else if (month1==4) {
System.out.println("星期一 星期二 星期三 星期四 星期五 星期六 星期天");
System.out.
