public class LocalDate {
public static void main(String[] args) {
LocalDateTime localDateTime = LocalDateTime.now();
LocalDateTime plusDaysResult = localDateTime.plusDays(20L);
System.out.println("当前时间是 : " + localDateTime + "\n"
+ "当前时间加20天后为 : " + plusDaysResult + "\n");
}
}
int main()
{
int x,y;
printf("请输入第一个数:\n");
scanf("%d",&x);
printf("请输入第二个数:\n");
scanf("%d",&y);
prinf("相加:%d\n",x+y);
prinf("相减:%d\n",x-y);
prinf("相乘:%d\n",x*y);
prinf("相除:%.2f\n",x/(y*1.0));//把y*1.0转换成float类型的
printf("取余:%d",x%y);
}
package lxx;
import java.util.Scanner;
/**
* @author kangjiafu
* @date 2021/5/5 20:40
*/
public class main {
public static void main(String[] args) {
int totalDay = 0;
int dayOfWeek;
int day = 0;
int dayOfYear = 0;
Scanner cs = new Scanner(System.in);
System.out.print("请输入年:");
int year = cs.nextInt();
System.out.print("请输入月:");
int month = cs.nextInt();
boolean bool = false;
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
bool = true;
}
for (int i = 1900; i < year; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
totalDay += 366;
} else {
totalDay += 365;
}
}
for (int i = 1; i <= month; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;
case 2:
if (bool) {
day = 29;
break;
} else {
day = 28;
break;
}
}
if (i < month) {
dayOfYear += day;
}
totalDay += dayOfYear;
dayOfWeek = (1 + totalDay) % 7;
System.out.println("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
for (int i1 = 0; i < dayOfWeek; i++) {
System.out.print("\t");
}
for (int i1 = 1; i <= day; i++) {
if ((totalDay + i) % 7 == 6) {
System.out.print(i + "\n");
} else {
System.out.print(i + "\t");
}
}
}
}
}
public class Cat {
String name;
String color;
int age;
public void xingMing(){
System.out.println("妮妮");
}
public void hanJiao(){
System.out.println("喵");
}
}
public class CatTest {
public static void main(String[] args){
Cat c=new Cat();
c.name="妮妮";
c.color="灰色";
c.age=2;
System.out.println("该猫的颜色为:"+c.color);
System.out.println("该猫的年龄为:"+c.age+"岁");
c.xingMing();
c.hanJiao();
}
}
public class main {
private String chepaihao;
private int chesu;
private double zaizhong;
public String getChepaihao() {
return chepaihao;
}
public void setChepaihao(String chepaihao) {
this.chepaihao = chepaihao;
}
public int getChesu() {
return chesu;
}
public void setChesu(int chesu) {
this.chesu = chesu;
}
public double getZaizhong() {
return zaizhong;
}
public void setZaizhong(double zaizhong) {
this.zaizhong = zaizhong;
}
public main()
{
chepaihao="XX231";
chesu=100;
zaizhong=100;
}
public main(String chepaihao, int chesu, double zaizhong) {
super();
this.chepaihao = chepaihao;
this.chesu = chesu;
this.zaizhong = zaizhong;
}
public void jiasu(int sudu)
{
if(sudu<0)
{
System.out.println("无法加速");
}
else
{
chesu+=sudu;
}
}
public void jiansu(int sudu)
{
if(sudu<0)
{
System.out.println("无法减速");
}
else
{
if((chesu-sudu)<0)
{
System.out.println("减速失败");
}
else
{
chesu-=sudu;
}
}
}
}
public class che {
public static void main(String[] args) {
main che1=new main();
che1.setChepaihao("豫k5651");
che1.jiasu(30);
System.out.println("车牌号="+che1.getChepaihao());
System.out.println("当前车速="+che1.getChesu());
System.out.println("载重="+che1.getZaizhong());
main che2=new main("豫j0394",120,200);
che2.jiansu(20);
System.out.println("车牌号="+che2.getChepaihao());
System.out.println("当前车速="+che2.getChesu());
System.out.println("载重="+che2.getZaizhong());
}
}
6.封装的作用
(1)便于使用者正确使用系统,防止错误修改属性
(2)降低了构建大型系统的风险
(3)提高程序的可重用性
(4)降低程序之间的耦合度
7.C