1
单向if语句
双向if语句
dangling else
switch:char,byte,short,int
2
javax.swing.JOptionPane.showConfirmDialog(null,text);
返回值:
JOptionPane.YES_OPTION:0
JOptionPane.NO_OPTION:1
JOptionPane.CANCEL_OPTION:2
3
cannot cast int from boolean
cannot cast boolean from int
4
%b
5
printf("%f",2);
java.util.IllegalFormatConversionException
6
java基本是值传参,基本类型不可改,需要Integer,Double打包,
Field f = r1.getClass().getDeclaredField("value");
f.setAccessible(true);
f.setDouble(r1.r1+1);
同时不能使用拷贝构造函数 public static boolean calEquRoot(double a,double b,double c,Double r1,Double r2) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
double delta = a * a - 4 * b * c;
if(delta < 0)return false;
delta=Math.sqrt(delta);
Field f=r1.getClass().getDeclaredField("value");
//r1=Double.valueof(1.0);r2=Double.valueof(2.0);
f.setAccessible(true);
f.setDouble(r1,Double.valueOf((-b+delta)/2/a));
f.setDouble(r2,Double.valueOf((-b-delta)/2/a));
return true;
} String类型为不可变字符串,传入也不改变其值 Keyword:
Boolean expression
Boolean value
boolean type
break statement
conditional operator
dangling-else ambiguity
fall-through behavior:语句从匹配处开始执行,直到遇到break语句或是达到switch语句的末端。
operator associativity
operator precedence
selection statement
short-circuit evaluation 3.1
< <= >= != == >
3.2
cannot cast
3.3
30 is even
30 is odd
________________
30 is even
3.4
z is 5
________________
z is 7
________________
x is 2
3.5
a==c==d
缩进正确:b,c
3.6
.............
3.7
等价
3.8
0.5,0.0,0.234
3.9
Math.random()*20;
Math.random()*10+10;
Math.random()*40+10;
3.10
if(y > 0)x=1;
3.11
if(score > 90)pay+=1.03; if(score > 90)pay+=1.03;
else pay*=1.01;
3.12
if (score >= 90.0)grade = 'A';
else if (score >= 80.0)grade = 'B';
else if (score >= 70.0)grade = 'C';
else if (score >= 60.0)grade = 'D';
else grade = 'F';
3.13
boolean fl = count % 10 == 0;
if (fl)newLine = true;
else newLine = false;
3.14
false,false,true,true,true,true,
3.15
x >= 1 && x <= 100
3.16
(x >= 1 && x <= 100) || x<0
3.17
x = y && y
x /= y
(x != 0) || (x = 0)
3.18
2
2
3.19
true,false,true,false
3.20
(x < y && y < z) is true
(x < y || y < z) is true
!(x < y) is false
(x + y < z) is false
(x + y < z) is false
3.21
age > 13 && age < 18
3.22
weight > 50 || height > 160
3.23
weight > 50 && height > 160
3.24
weight > 50 ^ height > 160
3.25
char,byte,int,long
下一个标签内的语句
可以
可能不行
格式紧凑,可读性好
3.26
2
3.27
switch(a){
case 1:
x+=5;
break;
case 2:
x+=10;
break; case 3:
x+=16;
break; case 4:
x+=34;
}
3.28
switch(day){
case 0:
dayName = "Sunday";
break;
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
}
3.29
System.out.print(count + count % 10 ==0?"\n":" ");
3.30
pay*=(temperature > 90?1.5:1.1);
3.31
%b %c %d %f %s
3.32
变参个数多
变参个数少
java.util.IllegalFormatConversionException
3.33
amount is 32.32 3.232000e+01
amount is 32.3200 3.2320e+01
false
Java
falseJava
false Java
3.35
true
true
3.36
假,赋值运算符(简捷运算符/=...)
3.37
false
false
3.38
yes,yes,yes
3.39
javax.swing.JOptionPane.showConfirmDialog(null,confirmMessage);
JOptionPane.YES_OPTION:0
JOptionPane.NO_OPTION:1
JOptionPane.CANCEL_OPTION:2 3.1
import java.lang.reflect.Field;
import java.util.Scanner;
import java.text.*; public class Exercise {
public static int calEquRoot(double a,double b,double c,Double r1,Double r2) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ double delta = b * b - 4 * a * c;
if(delta < 0)return -1;
delta=Math.sqrt(delta);
Field f=r1.getClass().getDeclaredField("value");
f.setAccessible(true);
f.setDouble(r1,Double.valueOf((-b+delta)/2/a));
f.setDouble(r2,Double.valueOf((-b-delta)/2/a));
if(delta < 1e-10)return 0;
return 1;
}
public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
double a,b,c;
Double r1 = Double.valueOf(0),r2 = Double.valueOf(0);
Scanner scanner = new Scanner(System.in);
System.out.println("Input a:");
a = scanner.nextDouble();
System.out.println("Input b:");
b = scanner.nextDouble();
System.out.println("Input c:");
c = scanner.nextDouble();
int fl=calEquRoot(a,b,c,r1,r2);
if(fl == 1){
System.out.println(r1);
System.out.println(r2);
}
else if(fl == 0){
System.out.println(r1);
}
else {
System.out.println("NO ROOT");
}
}
}
3.9
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) throws Exception{
Scanner scanner = new Scanner(System.in);
int[] a = new int[9];
int ans=0;
String tmp=scanner.next();
for(int i=0;i<9;i++){
a[i]=tmp.charAt(i)-'0';
ans+=(a[i] * (i + 1)) % 11;
}
ans%=11;
System.out.println(tmp+ans);
}
}
3.17
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) throws Exception{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
int r = (int)Math.random() * 3;
String[] srp={"scissor","rock","paper"};
String[] result={"You won","You lose","It is a draw"};
System.out.print("scissor(0), rock(1), paper(2): ");
int a;
while((a=scanner.nextInt())<=2 && a>=0){
System.out.print("The computer is "+srp[r]+". You are "+srp[a]+(a==r?" too. ":". ")
+ (a==r?result[2]:(a-r==1||a-r==-2)?result[0]:result[1]));
}
}
}
3.20
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) throws Exception{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the temperature in Fahrenheit: ");
double ta;
while((ta=scanner.nextDouble()) < -58||ta > 41){
System.out.print("Enter the temperature in Fahrenheit bewteen -58 and 41: ");
}
double v;
System.out.print("Enter the wind speed miles per hour: ");
while((v=scanner.nextDouble()) < 2){
System.out.print("Enter the wind speed miles per hour above 2 miles/h: ");
}
double ans=35.74 + 0.6215 * ta - 35.75 * Math.pow(v, 0.16) + 0.4275 * ta * Math.pow(v, 0.16);
System.out.println("The wind chill index is "+ans);
}
}
3.21
import java.util.Scanner;
public class Exercise {
/**
* 泽勒一致性
* */
public static void main(String[] args) throws Exception{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
int year,month,day,week;
System.out.print("Enter year: ");
year = scanner.nextInt();
System.out.print("Enter month: ");
month = scanner.nextInt();
if(month < 3)month+=12;
System.out.print("Enter the day of the month: ");
day = scanner.nextInt();
String[] date = {
"Saturday","Sunday",
"Monday","Tuesday","Wednesday",
"Thursday","Friday"
};
week = (day + 26*(month + 1)/10 + year % 100 + year % 100 / 4 + year/400 + year/100*5)%7;
System.out.println("Day of the week is " + date[week]);
}
}
3.22
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) throws Exception{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
double x,y;
System.out.print("Enter a point with two coordinates: ");
x = scanner.nextDouble();
y = scanner.nextDouble();
if(x * x + y * y <= 100){
System.out.println("Point ("+x+", "+y+") is in the circle");
}
else {
System.out.println("Point ("+x+", "+y+") is not in the circle");
}
}
}
3.27
import java.util.Scanner;
public class Exercise {
final static double eps=1e-16;
public static boolean judge(double a,double b,double x,double y){
if(Math.abs(a - b) < eps && a < eps ){
if(Math.abs(x - y) < eps && x < eps){
return true;
}
else return false;
}
else{
boolean fl = a * b < 0;
boolean fl2 = (b * x + a * y - a * b) > 0;
if(fl^fl2){
return false;
}
else return true;
}
}
public static void main(String[] args) throws Exception{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
double x,y;
System.out.print("Enter a point with two coordinates: ");
x = scanner.nextDouble();
y = scanner.nextDouble();
if(judge(200,100,x,y)){
System.out.println("Point ("+x+", "+y+") is in the circle");
}
else {
System.out.println("Point ("+x+", "+y+") is not in the circle");
}
}
}
3.28
import java.util.Scanner;
public class Exercise {
final static double eps=1e-16;
public static int judge(double[] w,double[] h,double[] x,double[] y){
w[0]/=2;w[1]/=2;h[0]/=2;h[1]/=2;
double dx = Math.abs(x[0] - x[1]);
double dy = Math.abs(y[0] - y[1]);
if(dx > w[0] + w[1]||dy > h[0] + h[1])return 0;
if(dx > w[0]||dy > h[0])return 2;
return 1;
}
public static void main(String[] args) throws Exception{
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
double[] x = new double [2],y = new double [2],w = new double [2],h = new double [2];
System.out.println("Enter r1's center x-, y-coordinates, width, and height: ");
x[0] = scanner.nextDouble();
y[0] = scanner.nextDouble();
w[0] = scanner.nextDouble();
h[0] = scanner.nextDouble();
System.out.println("Enter r2's center x-, y-coordinates, width, and height: ");
x[1] = scanner.nextDouble();
y[1] = scanner.nextDouble();
w[1] = scanner.nextDouble();
h[1] = scanner.nextDouble();
int fl;
if((fl = judge(w,h,x,y)) == 0){
System.out.println("r2 does not overlap r1");
}
else if(fl == 1){
System.out.println("r2 is inside r1");
}
else {
System.out.println("r2 overlaps r1");
}
}
}

  

java程序设计基础篇 复习笔记 第三单元的更多相关文章

  1. java程序设计基础篇 复习笔记 第七单元&&第八单元

    7.1 int[][] triArray{ {1}, {1,2}, {1,2,3}, }; 7.2 array[2].length 8.1 Unified Modeling Language:UML ...

  2. java程序设计基础篇 复习笔记 第六单元

    第六章 一维数组 1 数组初始化语法 array initializer 2 for each loop 3 off-by-one error 通常是在循环中该使用<的地方使用了<= 4 ...

  3. java程序设计基础篇 复习笔记 第五单元

    1. method header: modifier, return value type, method signature(method name, parameter) method body ...

  4. java程序设计基础篇 复习笔记 第四单元

    1 think before coding code incrementally 2 sentinel value sentinel-controlled loop 3 输入输出重定向 > &l ...

  5. java程序设计基础篇 复习笔记 第一单元

    java语言程序设计基础篇笔记1. 几种有名的语言COBOL:商业应用FORTRAN:数学运算BASIC:易学易用Visual Basic,Delphi:图形用户界面C:汇编语言的强大功能和易学性,可 ...

  6. java程序设计基础篇 复习笔记 第二单元

    1原始数据类型(primitive data type) == 基本类型 (fundamental type)byte short int long float double char boolean ...

  7. Java程序设计基础作业目录(作业笔记)

    持续更新中............. Java程序设计基础笔记 • [目录] 我的大学笔记>>> 第1章 初识Java>>> 1.1.4 学生成绩等级流程图练习 1 ...

  8. Java程序设计基础笔记 • 【目录】

    持续更新中- 我的大学笔记>>> 章节 内容 实践练习 Java程序设计基础作业目录(作业笔记) 第1章 Java程序设计基础笔记 • [第1章 初识Java] 第2章 Java程序 ...

  9. Java程序设计基础笔记 • 【第7章 Java中的类和对象】

    全部章节   >>>> 本章目录 7.1 理解类和对象 7.1.1 对象 7.1.2 抽象与类 7.1.3 类与对象的关系: 7.2 Java中的类和对象 7.2.1 类的定义 ...

随机推荐

  1. jq--ajax中止请求

    比如我后端设置延迟3s再响应给前端,我用的是node之koa2 router.get('/vueDemo/getStudents', async ( ctx ) => { //延迟3s asyn ...

  2. NIO 01 (转)

    本文转自:http://www.cnblogs.com/littlehann/p/3720396.html 目录 1. NIO.NIO.2简介 2. NIO中的关键技术 1. NIO.NIO.2简介 ...

  3. 多路选择I/O

    多路选择I/O提供另一种处理I/O的方法,相比于传统的I/O方法,这种方法更好,更具有效率.多路选择是一种充分利用系统时间的典型. 1.多路选择I/O的概念 当用户需要从网络设备上读数据时,会发生的读 ...

  4. Spark高级数据分析· 6LSA

    潜在语义分析 wget http://dumps.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles-multistream.xml.bz ...

  5. PHP(Mysql/Redis)消息队列的介绍及应用场景案例

    在进行网站设计的时候,有时候会遇到给用户大量发送短信,或者订单系统有大量的日志需要记录,还有做秒杀设计的时候,服务器无法承受这种瞬间的压力,无法正常处理,咱们怎么才能保证系统正常有效的运行呢?这时候我 ...

  6. 20145329 《Java程序设计》第九周学习总结

    教材学习内容总结 十六章 1.Metadata即"诠读数据的数据",数据库是用来存储数据的地方,然而数据库本身产品名称为何?数据库中有几个数据表格?表格名称为何?表格中有几个字段等 ...

  7. Java 设计模式六原则及23中常用设计模式

    一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...

  8. CNN笔记:通俗理解卷积神经网络【转】

    本文转载自:https://blog.csdn.net/v_july_v/article/details/51812459 通俗理解卷积神经网络(cs231n与5月dl班课程笔记) 1 前言 2012 ...

  9. 混合开发的大趋势之一React Native之页面跳转

    转载请注明出处:王亟亟的大牛之路 最近事情有点多,没有长时间地连贯学习,文章也停了一个多礼拜,愧疚,有时间还是继续学习,继续写! 还是先安利:https://github.com/ddwhan0123 ...

  10. oracle的 分表 详解 -----表分区

    此文从以下几个方面来整理关于分区表的概念及操作:         1.表空间及分区表的概念         2.表分区的具体作用         3.表分区的优缺点         4.表分区的几种类 ...