Bolg作业01

  对于前三次的题目集,难度是一次比一次难,对于知识点的运用一次比一次强。第一次题目集中知识点的运用主要是对于编程的基本运用,类似,1.7:对一些数字进行排序,1.8,同过循环对三角形进行判断。涉及到的知识点有,数字的相加,字符串的输入输出,循环结构,判断结构,顺序结构。第二次题目集中运用的知识点,涉及到了ip地址的访问,对于数组的访问,对于方法的使用,如2.4,2.5。在第三次的题目集里面,涉及到了类的使用,通过第三次题目集,对于类的使用的熟练度更上一层楼。

  踩坑心得:在踩坑方面,我几乎是踩了所有的坑,在最开始的时候,很多知识都不会,几乎就是步步试雷,编译错误有很多,但是在不断的调整过后,在接下来的编程中,这样类似的错误就很少犯了。

在第一次题目集里面

1.7:

import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int arr[] = new int[x];
int i;
for( i = 0;i<x;i++) {
arr[i]=in.nextInt();
}
Arrays.sort(arr,0,x-1);
System.out.printf("The sorted numbers are:");
for(i = 0;i<x;i++) {
System.out.printf("%d ",arr[i]);
}
}
}

1.8:

import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
float a = scanner.nextFloat();
float b = scanner.nextFloat();
float c = scanner.nextFloat();
if((a>=1&&a<=200)&&(b>=1&&b<=200)&&(c>=1&&c<=200))
{
if(a>b)
{
float temp = a;
a=b;
b= temp;
}
if(a>c)
{
float temp = a;
a=c;
c= temp;
}
if(b>c)
{
float temp = b;
b=c;
c= temp;
}
if(a+b>c)
{
if(a*a+b*b==c*c)
{
if(a==b)
System.out.println("Isosceles right-angled triangle");
else
System.out.println("Right-angled triangle");
}
else
if(a==b)
{
if(b==c)
{
System.out.println("Equilateral triangle");
}
else
{
System.out.println("Isosceles triangle");
}
}
else
System.out.println("Isosceles triangle");

}
else
{
System.out.println("General triangle");
}
}
else
System.out.println("Wrong Format");
}
}

第二次题目集中

7-4:

import java.util.Scanner;

public class Main
{

public static boolean isLeapYear(int year)
{
if(year % 4 == 0 && year % 100 !=0 ||year % 400 == 0)
{
return true;
}
else
{
return false;
}
}


public static boolean checkInputValidity(int year,int month,int day)
{
int[] arr=new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
if(isLeapYear(year)==true)
arr[2] = 29;
if(year>=1820&&year<=2020&&month>0&&month<=12&&day<=arr[month]&&day>0)
return true;
else
return false;
}

public static void nextDate(int year,int month,int day)
{

int[] arr=new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
if(isLeapYear(year)==true)
arr[2] = 29;
int a = 0,b = 0,c = 0;
if(checkInputValidity(year,month,day)==true) {
if(month==12) {
if(day==arr[month]) {
a = year+1;
b = 1;
c = 1;}
if(day>0&&day<arr[month])
{a = year;
b = month;
c =day +1;
}
}
if(month<12) {
if(day==arr[month]) {
a = year;
b = month + 1;
c = 1;}
if(day>0&&day<arr[month])
{a = year;
b = month;
c = day+1;
}
}
System.out.println("Next date is:"+a+"-"+b+"-"+c);
}
else System.out.println("Wrong Format");
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Main x = new Main();
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
x.nextDate(year,month,day);

}

}

7-5:

import java.util.Scanner;

public class Main
{

public static void main(String[] args)
{
int i=0,n=0,a=0,b=0,c=0,d=0,e=0;
Scanner sc = new Scanner(System.in);
a=sc.nextInt();
if(!(a>=1820&&a<=2020))
{
System.out.println("Wrong Format");
}
else
{
b=sc.nextInt();
if(!(b>=1&&b<=12))
{
System.out.println("Wrong Format");
}
else
{
c=sc.nextInt();
switch(b)
{
case 12:
case 10:
case 8:
case 7:
case 5:
case 3:
case 1:
if(!(c>=1&&c<=31))
e=1;
break;
case 11:
case 9:
case 6:
case 4:
if(!(c>=1&&c<=30))
e=1;
break;
case 2:
if((a%4==0&&a%100!=0)||a%400==0)
{
if(!(c>=1&&c<=29))
e=1;
}
else
{
if(!(c>=1&&c<=28))
e=1;
}
break;
}
if(e==1)
{
System.out.println("Wrong Format");
}
else
{
n=sc.nextInt();
if(!(n>=-10&&n<=10))
{
System.out.println("Wrong Format");
}
else
{
if(n>0)
{
if(n<c)
{
System.out.println(n+" days ago is:"+a+"-"+b+"-"+(c-n));
}
else if(n==c)
{
if((a%4==0&&a%100!=0)||a%400==0)
d=1;
switch(b)
{
case 1:
System.out.println(n+" days ago is:"+(a-1)+"-"+12+"-"+31);
break;
case 11:
case 9:
case 8:
case 6:
case 4:
case 2:
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+31);
break;
case 3:
if(d==1)
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+29);
else
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+28);
break;
case 12:
case 10:
case 7:
case 5:
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+30);
break;
}
}
else
{
if((a%4==0&&a%100!=0)||a%400==0)
d=1;
switch(b)
{
case 1:
System.out.println(n+" days ago is:"+(a-1)+"-"+12+"-"+(31-n+c));
break;
case 11:
case 9:
case 8:
case 6:
case 4:
case 2:
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+(31-n+c));
break;
case 3:
if(d==1)
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+(29-n+c));
else
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+(28-n+c));
break;
case 12:
case 10:
case 7:
case 5:
System.out.println(n+" days ago is:"+a+"-"+(b-1)+"-"+(30-n+c));
break;
}
}
}
else if(n==0)
{
System.out.println(n+" days ago is:"+a+"-"+b+"-"+(c-n));
}
else
{
if(c-n<=31)
{
if((a%4==0&&a%100!=0)||a%400==0)
d=1;
switch(b)
{
case 12:
case 10:
case 8:
case 7:
case 5:
case 3:
case 1:
System.out.println(n+" days ago is:"+a+"-"+b+"-"+(c-n));
break;
case 2:
if(d==1)
{
if(c-n<=29)
{
System.out.println(n+" days ago is:"+a+"-"+b+"-"+(c-n));
}
else
{
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-29));
}
}
else
{
if(c-n<=28)
{
System.out.println(n+" days ago is:"+a+"-"+b+"-"+(c-n));
}
else
{
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-28));
}
}
break;
case 11:
case 9:
case 6:
case 4:
if(c-n<=30)
{
System.out.println(n+" days ago is:"+a+"-"+b+"-"+(c-n));
}
else
{
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-30));
}
break;
}
}
else
{
if((a%4==0&&a%100!=0)||a%400==0)
d=1;
switch(b)
{
case 10:
case 8:
case 7:
case 5:
case 3:
case 1:
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-31));
break;
case 2:
if(d==1)
{
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-29));
}
else
{
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-28));
}
break;
case 11:
case 9:
case 6:
case 4:
System.out.println(n+" days ago is:"+a+"-"+(b+1)+"-"+(c-n-30));
break;
case 12:
System.out.println(n+" days ago is:"+(a+1)+"-"+1+"-"+(c-n-31));
break;
}
}
}
}
}
}
}
}
}

第三次题目集

import java.util.Scanner;

public class Main
{

public static void nextday(int year,int month,int day,int flag)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day==31)
{
if(month==12)
{
year=year+1;
month=1;
day=1;
}
else
{
month=month+1;
day=1;
}

}
else
day=day+1;
}
else
{
if(month==4||month==6||month==9||month==11)
{
if(day==30)
{
month=month+1;
day=1;
}
else
day=day+1;
}
else
{
if(flag==1)
{
if(day==29)
{
month=month+1;
day=1;
}
else
day=day+1;
}
else
{

if(day==28)
{
month=month+1;
day=1;
}
else
day=day+1;
}
}
}
System.out.println("Next day is:"+year+"-"+month+"-"+day);
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
int flag = 0;
if(year % 4 == 0 && year % 100 !=0 ||year % 400 == 0)
{
flag=1;
}
if((year<1900||year>2000)||(month<1||month>12)||(day<1||day>31))
System.out.println("Date Format is Wrong");
else
{
if(flag==1)
{
if(month==2)
{
if(day>29)
System.out.println("Date Format is Wrong");
else
nextday(year,month,day,flag);
}
else
nextday(year,month,day,flag);
}
else
{
if(month==2)
{
if(day>28)
System.out.println("Date Format is Wrong");
else
nextday(year,month,day,flag);
}
else
nextday(year,month,day,flag);
}
}

}

}

  改进意见:对于代码的编译,我觉得可以在一次题目集中,可以逐渐提高难度,后一道题在前一道题的基础上,增加新的要求,做到循序渐进。

  对于这三次题目集,我做一下总结,对于这三次题目集,让我对于java的理解更深,对于java的编程规则更加熟练,学习到了java不同于C语言的编程规则。学习到了java语言不同于C语言的编程优越性。对于java语言,在学习方面还需要进一步加强,在编程方面,多动手实践,实践是检验真理的唯一标准。对于教师方面,我提一点建议,就是,上课的时候课件字体能否做的大一点,有时候坐在前排都看不清,还有,希望老师讲课的时候,可以通过编程的方式来让我们了解到这个知识点的运用,了解到这个知识点能干什么,而不是就是在讲台上讲空话套话,对着屏幕上的字念,事实上有些时候根本就不懂,在其他的方面,我觉得挺好的。对于实验,觉得在pta上发布的效果更好一些。

posted @ 2021-04-04 21:22  身南心北  阅读(72)  评论(0)    收藏  举报