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

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

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

  • 62 次阅读
  • 3 次下载
  • 2025/5/6 8:10:18

\{font-family: \\\New\\\sans-serif; font-size: 100%; color: black}\);

output.format(\,

\); output.format(\, \); output.format(\, \);

// Match the color in the text

// output.format(\ // output.format(\

// output.format(\bold}\

output.format(\, \);

output.format(\, \); output.format(\, \); output.format(\, \);

String text = \; String temp;

// Read all lines

while (input.hasNext()) { temp = input.nextLine(); text += temp + \; }

text = text.replaceAll(\, \); text = text.replaceAll(\, \); translateToHTML(text, input, output);

output.format(\, \); output.format(\, \); output.format(\, \); }

catch (Exception ex) { System.out.println(ex); }

finally { try {

input.close(); output.close(); }

catch (Exception ex) { } } }

/** Translate Java source code to HTML */

static void translateToHTML(String text, Scanner input, PrintWriter output) throws Exception {

text = text.replaceAll(\, \); text = text.replaceAll(\, \);

String token;

while (text != null && text.length() > 0) { // * and / are in conflict with /* and //

String[] parts = text.split(\, 2);

token = parts[0];

if (token.length() > 1 && token.startsWith(\)) { output.format(\, \); parts = text.split(\, 2); text = parts[1];

output.format(\, parts[0].replaceAll(\, \)); output.format(\, \); continue; }

else if (token.length() > 1 && token.startsWith(\)) { output.format(\, \); parts = text.split(\, 2); text = parts[1];

output.format(\, parts[0].replaceAll(\, \) + \);

output.format(\, \); continue; }

else if (token.length() > 1 && token.matches(\)) { output.format(\, \); output.format(\, token); output.format(\, \); }

else if (token.startsWith(\) && token.endsWith(\) && (token.length() > 1)) {

output.format(\, \ + token + \); }

else if (token.startsWith(\) && token.endsWith(\) && (token.length() > 1)) {

output.format(\, \ + token + \); }

else if (token.equals(\)) {

output.format(\, \ + token + \); }

else if (token.startsWith(\) && token.endsWith(\) && (token.length() == 1)) { if (stringToken) {

output.format(\, token + \); stringToken = false; } else {

output.format(\, \ + token); stringToken = true; } }

else if (token.startsWith(\)) {

output.format(\, \ + token); stringToken = true; }

else if (token.endsWith(\) && (!token.endsWith(\))) { output.format(\, token); output.format(\, \); stringToken = false; }

else if (token.matches(\)) { // Check if numeric output.format(\, \ + token + \); }

else if (!stringToken && keywordSet.contains(token)) { output.format(\, \ + token + \); } else {

output.format(\, token); }

if (token.length() < text.length()) { if (text.charAt(token.length()) == '<') output.format(\, \);

else if (text.charAt(token.length()) == '>') output.format(\, \); else

output.format(\, text.charAt(token.length())); }

if (parts.length == 2) { text = parts[1]; } } } }

21.6

import java.util.*;

public class Exercise21_06 {

public static void main(String[] args) {

// Create a tree map to hold words and key and count as value TreeMap treeMap = new TreeMap<>();

Scanner input = new Scanner(System.in); while (true) { // Enter an integer

System.out.print(\); int number = input.nextInt();

if (number == 0) break;

Integer key = new Integer(number);

if (treeMap.get(key) != null) {

int value = ((Integer)treeMap.get(key)).intValue(); value++;

treeMap.put(key, new Integer(value)); } else {

treeMap.put(key, new Integer(1)); } }

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

共分享92篇相关文档

文档简介:

\{font-family: \\\New\\\sans-serif; font-size: 100%; color: black}\); output.format(\, \); output.format(\, \); output.format(\, \); // Match the color in the text // output.format(\ // output.format(\ // output.format(\bold}\ output.format(\, \); output.format(\, \); output.format(

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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