《Java语言程序设计(基础篇)》(第10版 梁勇 著)第一章练习题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《Java语言程序设计(基础篇)》(第10版梁勇著)
第一章练习题答案
1.1
public class Exercise01_01 {
public static void main(String[] args) {
System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");
}
}
1.1附加
public class Exercise01_01Extra {
public static void main(String[] args) {
System.out.println(4 * 4 - 4 * 3 * 5);
}
}
1.2
public class Exercise01_02 {
public static void main(String[] args) {
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
}
}
1.3
public class Exercise01_03 {
public static void main(String[] args) {
System.out.println(" J A V V A ");
System.out.println(" J A A V V A A ");
System.out.println("J J AAAAA V V AAAAA ");
System.out.println(" J J A A V A A ");
}
}
1.4
public class Exercise01_04 {
public static void main(String[] args) {
System.out.println("a a^2 a^3");
System.out.println("1 1 1");
System.out.println("2 4 8");
System.out.println("3 9 27");
System.out.println("4 16 64");
}
}
1.5
public class Exercise01_05 {
public static void main(String[] args) {
System.out.println((9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5)); }
}
1.6
public class Exercise01_06 {
public static void main(String[] args) {
System.out.println(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); }
}
1.7
public class Exercise01_07 {
public static void main(String[] args) {
System.out.println(4 * (1 - 1.0 / 3 + 1.0 / 5 - 1.0 / 7 +
1.0 / 9 - 1.0 / 11 + 1.0 / 13));
}
}
1.8
public class Exercise01_08 {
public static void main(String[] args) {
// Display area
System.out.println(5.5 * 5.5 * 3.14159);
// Display perimeter
System.out.println(2 * 5.5 * 3.14159);
}
}
1.9
public class Exercise01_09 {
public static void main(String[] args) {
// Display area
System.out.println(4.5 * 7.9);
// Display perimeter
System.out.println(2 * (4.5 + 7.9));
}
}
1.10
public class Exercise01_10 {
public static void main(String[] args) {
System.out.println((14 / 45.5) * 60 / 1.6);
}
}
1.11
public class Exercise01_11 {
public static void main(String[] args) {
System.out.println(312032486 + 365 * 24 * 60 * 60 / 7.0 - 365 * 24 * 60 * 60 / 13.0 + 365 * 24 * 60 * 60 / 45.0);
System.out.println(312032486 + 2 * 365 * 24 * 60 * 60 / 7.0 - 2 * 365 * 24 * 60 * 60 / 13.0 + 2 * 365 * 24 * 60 * 60 / 45.0);
System.out.println(312032486 + 3 * 365 * 24 * 60 * 60 / 7.0 - 3 * 365 * 24 * 60 * 60 / 13.0 + 3 * 365 * 24 * 60 * 60 / 45.0);
System.out.println(312032486 + 4 * 365 * 24 * 60 * 60 / 7.0 - 4 * 365 * 24 * 60 * 60 / 13.0 + 4 * 365 * 24 * 60 * 60 / 45.0);
System.out.println(312032486 + 5 * 365 * 24 * 60 * 60 / 7.0 - 5 * 365 * 24 * 60 * 60 / 13.0 + 5 * 365 * 24 * 60 * 60 / 45.0);
}
}