1  本题主要考的是方法的克隆,与c++里面的拷贝有点相似,具体看书本p147

 import java.util.Objects;

 public class Square implements Cloneable{
private int length; public Square(int length) {
this.length = length;
} @Override
public String toString() {
return "Square[" +
"length=" + length +
']';
} @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Square square = (Square) o;
return length == square.length;
} @Override
public int hashCode() {
return Objects.hash(length);
} public static void main(String[] args) throws CloneNotSupportedException{
Square s1=new Square(100);
Square s2=(Square)s1.clone();
System.out.println(s1==s2);
System.out.println(s1.equals(s2));
System.out.println(s2.toString()); }
}

2  本题水题,主要就是考数组,把产生的需求数存在数组里

 public class Suiji {
public static int a[]=new int[6];
public static void main(String[] args) {
Suiji s=new Suiji();
System.out.println("随机产生1000个1-6的数");
s.stc(6); for (int i = 1; i <=6 ; i++) {
System.out.println(i+"的概率是"+(a[i-1]*1.0/1000)*100+"%");
}
System.out.println("****************************");
System.out.println("随机产生1000个1-1000的数");
for (int i = 0; i < a.length; i++) {
a[i]=0;
}
s.stc(1000);
for (int i = 1; i <=6 ; i++) {
System.out.println(i+"的概率是"+(a[i-1]*1.0/1000)*100+"%");
} }
public void stc(int num){
for (int i = 0; i <1000 ; i++) {
switch ((int)(Math.random()*num+1)){
case 1:a[0]++;
break;
case 2:a[1]++;
break;
case 3:a[2]++;
break;
case 4:a[3]++;
break;
case 5:a[4]++;
break;
case 6:a[5]++;
break;
}
}
}
}

3  本题注意sinx x是弧度即可

 public class Area {
public static void main(String[] args) {
float a=4.0f,b=5.0f; float t= (float) Math.sin(30*(Math.PI/180));
// System.out.println("三角形的面积为:"+(1*1.0/2)*a*b*t);
System.out.println(((1*1.0/2)*a*b*t));
} }

4  本题只要记得如何求最大值、最小值的封装方法即可(MAX_VALUE、MIN_VALUE)

 public class Baozhuang {
// Integer integer;
public static void main(String[] args) {
Integer integer = null;
System.out.println("Integer的最大值"+integer.MAX_VALUE+"\t"+"Integer的最小值"+integer.MIN_VALUE);
Long l=null;
System.out.println("Long的最大值"+l.MAX_VALUE+"\t"+"Long的最小值"+l.MIN_VALUE);
Float f=null;
System.out.println("Float的最大值"+f.MAX_VALUE+"\t"+"Float的最小值"+f.MIN_VALUE);
Double d=null;
System.out.println("Double的最大值"+d.MAX_VALUE+"\t"+"Double的最小值"+d.MIN_VALUE);
Character character=null;
System.out.println(" Character的最大值"+character.MAX_VALUE+"\t"+" Character的最小值"+character.MIN_VALUE);
Byte b=null;
System.out.println(" Byte的最大值"+b.MAX_VALUE+"\t"+" Byte的最小值"+b.MIN_VALUE);
Short s=null;
System.out.println("Short的最大值"+s.MAX_VALUE+"\t"+" Short的最小值"+s.MIN_VALUE); }
}

5  本题自行百度查看

6  本题水题,plusDays就是给当前对象增加几天

 import java.text.ParseException;
import java.time.LocalDate;
public class ch06 {
public static void main(String[] args) throws ParseException {
LocalDate pday=LocalDate.of(2017,1,1).plusDays(256);
System.out.println(pday);
}
}

7  本题主要就是知道如何求天数,对什么值求模

 import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner; public class ch07 {
public static void main(String[] args) throws ParseException {
Scanner input =new Scanner(System.in);
String dbtime1 = input.next(); //第二个日期
String dbtime2 = input.next(); //第一个日期
//算两个日期间隔多少天
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = format.parse(dbtime1);
Date date2 = format.parse(dbtime2); int a = (int) ((date1.getTime() - date2.getTime()) / (1000*3600*24));
System.out.println(a);
}
}

8  本题具体自行查看书本p159

 import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.Scanner; public class PromtCalendar {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("输入一个年份(如2018):");
int year = input.nextInt(); for (int j = 1; j <=12; j++) {
// 返回本月第一天
LocalDate dates = LocalDate.of(year,j, 1);
String monthName = dates.getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault());
// 返回当月的天数
int dayOFmonth = dates.lengthOfMonth();
System.out.println(year + "年 " + monthName);
System.out.println("-------------------------------");
System.out.printf("%4s%3s%3s%3s%3s%3s%3s%n", "一", "二", "三", "四", "五", "六", "日");
int dayOfWeek = dates.getDayOfWeek().getValue();
for (int i = 2; i <= dayOfWeek; i++) {
System.out.printf("%4s", " ");
}
for (int i = 1; i <= dayOFmonth; i++) {
System.out.printf("%4d", i);
if ((dayOfWeek + i - 1) % 7 == 0)
System.out.println();
}
System.out.println();
}
}
}

9  本题主要考的数组里面值的存入问题,也可以用if语句逐一进行判断,注意要月份和天数都要满足

 import java.util.Scanner;

 public class xingzuo {
/* public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("输入一个年份(如2018):");
int year=input.nextInt();
int month = input.nextInt();
// 输入天数
int day = input.nextInt();
LocalDate dates3 = LocalDate.of(year, month, day).plusDays(30);
//dates3.plusDays(30);
System.out.println(dates3); LocalDate[] desk = {LocalDate.of( 0,3, 20), LocalDate.of(0, 4, 20),
LocalDate.of(0, 4, 19), LocalDate.of(0, 4, 21),
LocalDate.of(0, 5, 20), LocalDate.of(0, 6, 22),
LocalDate.of(0, 6, 21), LocalDate.of(0, 7, 23),
LocalDate.of(0, 7, 22), LocalDate.of(0, 8, 23),
LocalDate.of(0, 8, 22), LocalDate.of(0, 9, 24),
LocalDate.of(0, 9, 22), LocalDate.of(0, 10, 24),
LocalDate.of(0, 10, 23), LocalDate.of(0, 11, 23),
LocalDate.of(0, 11, 22), LocalDate.of(0, 12, 22),
LocalDate.of(0, 12, 21), LocalDate.of(0, 1, 20),
LocalDate.of(0, 1, 19), LocalDate.of(0, 2, 19),
LocalDate.of(0, 2, 18), LocalDate.of(0, 3, 21)}; if (dates3.isAfter(desk[0]) && dates3.isBefore(desk[1])) { System.out.println("白羊座" );
}
else if (dates3.isAfter(desk[2]) && dates3.isBefore(desk[3])){
System.out.println("金牛座");
}
else if (dates3.isAfter(desk[4]) && dates3.isBefore(desk[5])){
System.out.println("双子");
}
else if (dates3.isAfter(desk[6]) && dates3.isBefore(desk[7])){
System.out.println("巨蟹");
}
else if (dates3.isAfter(desk[8]) && dates3.isBefore(desk[9])){
System.out.println("狮子");
}
else if (dates3.isAfter(desk[10]) && dates3.isBefore(desk[11])){
System.out.println("处女");
}
else if (dates3.isAfter(desk[12]) && dates3.isBefore(desk[13])){
System.out.println("天平");
}
else if (dates3.isAfter(desk[14]) && dates3.isBefore(desk[15])){
System.out.println("天蝎");
}
else if (dates3.isAfter(desk[16]) && dates3.isBefore(desk[17])){
System.out.println("射手");
}
else if (dates3.isAfter(desk[18]) && dates3.isBefore(desk[19])){
System.out.println("摩羯");
}
else if (dates3.isAfter(desk[20]) && dates3.isBefore(desk[21])){
System.out.println("水平");
}
else if (dates3.isAfter(desk[22]) && dates3.isBefore(desk[23])){
System.out.println("双鱼");
}
}*/ public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("请输入出生日期如(5 20)");
System.out.println(
getConstellation(input.nextInt(),input.nextInt())
);
}
private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 };
private final static String[] constellationArr = new String[] { "摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座" };
public static String getConstellation(int month, int day) {
return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month];
}
}

最新文章

  1. php面试题
  2. jexus部署ASP.NET MVC网站
  3. 【转】NHibernate:no persister for 异常
  4. myeclipse10安装findbugs
  5. sqlserver 计算 百分比
  6. XE7 - Image的双击事件无响应,咋整?(已解决)
  7. C#学习日志 day10 -------------- problem statement
  8. [置顶] hdu3018解题报告--也是白话几笔画学习总结
  9. PL SQL Developer报错框乱码
  10. 翻译:如何使用CSS实现多行文本的省略号显示
  11. OpenCV3.0 HDR(高动态范围)示例代码以及用法
  12. iOS-FMDB事务【批量更新数据】
  13. logstash分析日志
  14. GNSS相关网站汇总
  15. Oracle 存储过程 PROCEDURE
  16. qt程序编译错误:could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake’
  17. 不能ping通主机名
  18. 【HDU4947】GCD Array (莫比乌斯反演+树状数组)
  19. 瑞联科技:Pwp3框架 调用存储过程返还数据集合 到前端界面展示
  20. ajax补充--------FormData等...

热门文章

  1. Qt编写自定义控件33-图片切换动画
  2. SQL Server 高级函数汇总【转】
  3. C#创建windows服务(二:创建和卸载windows服务)
  4. [C++]多源最短路径(带权有向图):【Floyd算法(动态规划法)】 VS n*Dijkstra算法(贪心算法)
  5. seaborn可视化
  6. golang web框架设计5:配置设计
  7. centos(linux)-maven配置
  8. JAVA计算字符串UTF-8字节数
  9. emacs 常用命令
  10. springboot+JPA 整合redis