ImageVerifierCode 换一换
格式:DOCX , 页数:54 ,大小:27.80KB ,
资源ID:444202      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/444202.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(《Java语言程序设计基础篇》第10版 梁勇 著第十二章练习题答案.docx)为本站会员(b****2)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

《Java语言程序设计基础篇》第10版 梁勇 著第十二章练习题答案.docx

1、Java语言程序设计基础篇第10版 梁勇 著第十二章练习题答案Java语言程序设计(基础篇)(第10版 梁勇 著)第十二章 练习题答案12.1public class Exercise12_01 public static void main (String args) int num1, num2, result = 0; if (args.length != 3) System.out.println( please use java Exercise12_01 operand1 operator operand2); System.exit(1); try num1 = Integer.

2、parseInt(args0); catch (NumberFormatException ex) System.out.println(Wrong Input: + args0); return; try num2 = Integer.parseInt(args2); catch (Exception ex) System.out.println(Wrong Input: + args2); return; switch (args1.charAt(0) case +: result = num1 + num2; break; case -: result = num1 - num2; br

3、eak; case .: result = num1 * num2; break; case /: result = num1 / num2; System.out.println(args0 + + args1 + + args2 + = + result); 12.1附加import java.util.Scanner;import java.util.ArrayList;import java.io.*;public class Exercise12_01Extra public static void main(String args) throws IOException Scann

4、er input = new Scanner(System.in); System.out.print(Enter a file name for baby name ranking: ); File file = new File(input.nextLine(); if (!file.exists() System.out.println(File + file + does not exist); System.exit(1); / Open the file input = new Scanner(file); ArrayList boyNames = new ArrayList();

5、 ArrayList girlNames = new ArrayList(); while (input.hasNext() input.nextInt(); / Skip an integer for ranking boyNames.add(input.next(); input.nextInt(); / Skip an integer for number of boys girlNames.add(input.next(); input.nextInt(); / Skip an integer for number of girls boyNames.retainAll(girlNam

6、es); / If you dont know how to use the retainAll method, write your own code to obtain the common elements in two array lists. System.out.println(boyNames.size() + names are used for both boys and girls ); System.out.println(They are ); for (String name: boyNames) System.out.print(name + ); 12.2impo

7、rt java.util.Scanner;public class Exercise12_02 public static void main(String args) Scanner input = new Scanner(System.in); boolean done = false; int number1 = 0; int number2 = 0; / Enter two integers System.out.print(Enter two integers: ); while (!done) try number1 = input.nextInt(); number2 = inp

8、ut.nextInt(); done = true; catch (Exception ex) ex.printStackTrace(); System.out.print(Incorrect input and re-enter two integers: ); input.nextLine(); / Discard input System.out.println(Sum is + (number1 + number2); 12.2附加import java.util.*;import java.io.*;public class Exercise12_02Extra private st

9、atic ArrayList names = new ArrayList(); private static void readNames() try for (int i = 0; i 10; i+) String filename; if (i = 9) filename = Babynamesranking2010.txt; else filename = Babynamesranking200 + (i + 1) + .txt; Scanner input = new Scanner(new File(filename); while (input.hasNext() input.ne

10、xtInt(); / Skip the ranking String name = input.next(); if (!names.contains(name) names.add(name); input.nextInt(); / Skip the number of boys name name = input.next(); if (!names.contains(name) names.add(name); input.nextInt(); / Skip the number of girls name catch (Exception ex) ex.printStackTrace(

11、); /* Main method */ public static void main(String args) readNames(); Collections.sort(names); / If you dont know how to use this method, write your own method to sort the elements in an array list writeNames(); private static void writeNames() try PrintWriter output = new PrintWriter(AllBabyNamesS

12、ortedDuplicatesNotAllowed.txt); for (int i = 1; i = names.size(); i+) if (i % 10 = 0) output.println(names.get(i - 1); else output.print(names.get(i - 1) + ); output.close(); System.out.println(Done); catch (Exception ex) ex.printStackTrace(); 12.3 import java.util.*;public class Exercise12_03 publi

13、c static void main(String args) int data = new int100; / Initialize array for (int i = 0; i 100; i+) datai = (int)(Math.random() * 10000); Scanner input = new Scanner(System.in); System.out.print(Enter an index: ); int index = input.nextInt(); try System.out.println(The element is + dataindex); catc

14、h (Exception ex) System.out.println(Index out of bound); 12.3附加import java.util.*;import java.io.*;public class Exercise12_03Extra private static String names = new String1000 * 10 * 2; private static void readNames() try int j = 0; for (int i = 0; i 10; i+) String filename; if (i = 9) filename = Babynamesranking2010.txt; e

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1