云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 《Java语言程序设计(基础篇)》(第10版 梁勇 著)第二十一章练习题答案

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

  • 62 次阅读
  • 3 次下载
  • 2025/5/6 8:03:50

{\, \}, {\, \}, {\, \},

{\, \}, {\, \},

{\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \} };

Map map = new HashMap();

for (int i = 0; i < stateCapital.length; i++)

map.put(stateCapital[i][0].toLowerCase(), stateCapital[i][1]);

Scanner input = new Scanner(System.in); System.out.print(\);

String state = input.nextLine().toLowerCase().trim(); if (map.containsKey(state))

System.out.println(\ + map.get(state)); else

System.out.println(\); } }

21.10

import java.util.*; import java.io.*;

public class Exercise21_10 {

public static void main(String[] args) {

// Prompt the user to enter a Java source file

Scanner input = new Scanner(System.in); System.out.print(\); String filename = input.nextLine();

// Array of all Java keywords + true + null

String[] keywordString = { \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \ };

Set keywordSet = new

HashSet(Arrays.asList(keywordString)); int count = 0;

try {

input = new Scanner(new File(filename));

String text = \;

while (input.hasNext()) {

String line = input.nextLine(); line = stripLineComments(line); line = stripLineStringLiterals(line); text += line + \; }

text = stripParagraghComments(text);

TreeMap map = new TreeMap();

String[] tokens = text.split(\); for (String token : tokens) { if (keywordSet.contains(token)) if (map.get(token) == null) { map.put(token, 1); } else {

int value = map.get(token); value++;

map.put(token, value); } }

// Get all entries into a set

Set> entrySet = map.entrySet();

// Get key and value from each entry

for (Map.Entry entry: entrySet)

System.out.println(entry.getValue() + \ + entry.getKey()); } catch (Exception ex) { ex.printStackTrace(); } }

/* Strip line comments */

private static String stripLineComments(String line) { int index = line.indexOf(\);

if (index < 0) return line; else

return line.substring(0, index); }

/* Strip string literals */

private static String stripLineStringLiterals(String line) { int start = line.indexOf(\);

int end = line.indexOf(\, start + 1);

while (start > 0 && end > 0) {

line = line.substring(0, start) + line.substring(end + 1); start = line.indexOf(\); end = line.indexOf(\); }

return line; }

/* Strip paragraph comments */

private static String stripParagraghComments(String text) { int start = text.indexOf(\); int end = text.indexOf(\);

while (start > 0 && end > 0) {

text = text.substring(0, start) + text.substring(end + 2); start = text.indexOf(\);

end = text.indexOf(\); }

return text; } }

21.11

import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.Scanner;

import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene;

import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.stage.Stage;

public class Exercise21_11 extends Application {

private Map[] mapForBoy = new HashMap[10]; private Map[] mapForGirl = new HashMap[10];

private Button btFindRanking = new Button(\); private ComboBox cboYear = new ComboBox<>(); private ComboBox cboGender = new ComboBox<>(); private TextField tfName = new TextField(); private Label lblResult = new Label();

@Override // Override the start method in the Application class public void start(Stage primaryStage) { GridPane gridPane = new GridPane();

gridPane.add(new Label(\), 0, 0); gridPane.add(new Label(\), 0, 1); gridPane.add(new Label(\), 0, 2); gridPane.add(cboYear, 1, 0); gridPane.add(cboGender, 1, 1); gridPane.add(tfName, 1, 2); gridPane.add(btFindRanking, 1, 3);

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

{\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \}, {\, \} }; Map map = new HashMap(); for (int i = 0; i < stateCapital.length;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com