Java语言程序设计与数据结构(基础篇)课后练习题 第十二章(四)

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
img

正文

import java.net.URL;

import java.util.Scanner;

public class dishierzhang {

public static void main(String[] args) throws Exception {

double salaryAssistant = 0;

int countAssistant = 0;

double salaryAssociate = 0;

int countAssociate = 0;

double salaryFull = 0;

int countFull = 0;

double SalaryQuantity = 0;

URL url = new URL(“http://liveexample.pearsoncmg.com/data/Salary.txt”);

String s = null;

try (Scanner input = new Scanner(url.openStream())😉 {

while (input.hasNext()) {

s = input.nextLine();

String[] s1 = s.split(" ");

SalaryQuantity = Double.valueOf(s1[s1.length - 1]);

if (s1[s1.length - 2].equalsIgnoreCase(“assistant”)) {

salaryAssistant += SalaryQuantity;

countAssistant++;

} else if (s1[s1.length - 2].equalsIgnoreCase(“associate”)) {

salaryAssociate += SalaryQuantity;

countAssociate++;

} else if (s1[s1.length - 2].equalsIgnoreCase(“full”)) {

salaryFull += SalaryQuantity;

countFull++;

}

s = null;

}

}

System.out.println("Count: " + countAssistant + ", Salary: " + salaryAssistant + ", Aver: "

  • salaryAssistant / countAssistant);

System.out.println("Count: " + countAssociate + ", Salary: " + salaryAssociate + ", Aver: "

  • salaryAssociate / countAssociate);

System.out.println("Count: " + countFull + ", Salary: " + salaryFull + ", Aver: " + salaryFull / countFull);

}

}

12.26

==================================================================

import java.io.File;

import java.util.Scanner;

public class dishierzhang {

public static void main(String[] args) throws Exception {

Scanner input = new Scanner(System.in);

System.out.print("Enter a directory: ");

String s = input.next();

File file = new File(s);

if (file.mkdir()) {

System.out.println(“Directory created successfully”);

} else {

System.out.println(“Directory already exists”);

}

}

}

12.27

==================================================================

12.28

==================================================================

import java.io.File;

import java.util.Scanner;

public class dishierzhang {

public static void main(String[] args) throws Exception {

Scanner input = new Scanner(System.in);

System.out.print(“Enter a file path:”);

File file = new File(path(input.next()));

renameFile(file);

}

public static String path(String path) {

return path.replaceAll(“\\”, “/”);

}

public static void renameFile(File file) {

if (getNewName(file).equals(“gg”)) {

if (file.isFile()) {

return;

} else {

directory(file);

}

} else if (file.isDirectory()) {

directory(file);

file(file);

} else if (file.isFile()) {

file(file);

}

}

public static File file(File file) {

File newFile = new File(getNewName(file));

System.out.println(newFile.getAbsolutePath() + " " + file.renameTo(newFile));

return newFile;

}

public static void directory(File file) {

File[] subFile = file.listFiles();

System.out.println(file.getAbsolutePath());

for (File everyFile : subFile) {

renameFile(everyFile);

}

}

public static String getNewName(File file) {

String name = path(file.getAbsolutePath());

String newName = null;

if (!name.contains(“Exercise”)) {

return “gg!”;

}

String tail = name.substring(name.lastIndexOf(“Exercise”), name.length());

if (tail.contains(“.”)) {

String[] countNum = tail.split(“[ercise_.]”);

if (countNum[countNum.length - 3].length() == 1) {

countNum[countNum.length - 3] = “0” + countNum[countNum.length - 3];

}

newName = name.substring(0, name.lastIndexOf(“Exercise”)) + “Exercise” + countNum[countNum.length - 3] + “_”

  • countNum[countNum.length - 2] + “.” + countNum[countNum.length - 1];

} else {

String[] countNum = tail.split(“[ercise_]”);

if (countNum[countNum.length - 2].length() == 1) {

countNum[countNum.length - 2] = “0” + countNum[countNum.length - 2];

}

newName = name.substring(0, name.lastIndexOf(“Exercise”)) + “Exercise” + countNum[countNum.length - 2] + “_”

  • countNum[countNum.length - 1];

}

return newName;

}

}

12.29

==================================================================

12.30

==================================================================

import java.io.File;

import java.util.Scanner;

public class dishierzhang {

public static void main(String[] args) throws Exception {

int[] alphabet = new int[26];

Scanner input = new Scanner(System.in);

System.out.print("Enter a filename: ");

String s = input.next();

File file = new File(s);

if(!file.exists()){

System.out.println(“Not Exist!”);

System.exit(1);

}

Scanner output = new Scanner(file);

while(output.hasNextLine()){

String l = output.nextLine().toUpperCase();

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

if(Character.isLetter(l.charAt(i)))

alphabet[l.charAt(i)-‘A’]++;

}

for(int i=0;i<26;i++)

System.out.println("Number of "+(char)(i+‘A’)+"s: "+alphabet[i]);

}

}

12.31

==================================================================

这个题感觉有点问题,中间split分裂后的数组s1[1]和s1[2]特别奇怪。。。。。差点给我搞吐了,不过还是做出来了,搞定!

import java.net.URL;

import java.util.Scanner;

public class dishierzhang {

public static void main(String[] args) throws Exception {

Scanner input = new Scanner(System.in);

System.out.print("Enter the year: ");

String year = input.next();

System.out.print("Enter the gender: ");

String gender = input.next(); //M是男,F是女。

System.out.print("Enter the name: ");

String name = input.next();

URL url = new URL(“http://liveexample.pearsoncmg.com/data/babynamesranking” + year + “.txt”);

String s = null;

try (Scanner input1 = new Scanner(url.openStream())😉 {

while (input1.hasNextLine()) {

s = input1.nextLine();

String[] s1 = s.split(" ");

if (gender.equals(“M”)) {

if (s1[1].matches(“(.)" + name + "(.)”)) {

System.out.print(name + " is ranked #" + s1[0] + " in vear " + year);

System.exit(0);

}

} else if (gender.equals(“F”)) {

if (s1[2].matches(“(.)" + name + "(.)”)) {

System.out.print(name + " is ranked #" + s1[0] + " in vear " + year);

System.exit(0);

}

} else {

System.out.println(“Wrong,gender!”);

System.exit(1);

}

s = null;

}

}

System.out.println("The name " + name + " is not ranked in vear " + year);

}

}

12.32

==================================================================

照着上面的代码,自己改改吧。

最后

分享一套我整理的面试干货,这份文档结合了我多年的面试官经验,站在面试官的角度来告诉你,面试官提的那些问题他最想听到你给他的回答是什么,分享出来帮助那些对前途感到迷茫的朋友。

面试经验技巧篇
  • 经验技巧1 如何巧妙地回答面试官的问题
  • 经验技巧2 如何回答技术性的问题
  • 经验技巧3 如何回答非技术性问题
  • 经验技巧4 如何回答快速估算类问题
  • 经验技巧5 如何回答算法设计问题
  • 经验技巧6 如何回答系统设计题
  • 经验技巧7 如何解决求职中的时间冲突问题
  • 经验技巧8 如果面试问题曾经遇见过,是否要告知面试官
  • 经验技巧9 在被企业拒绝后是否可以再申请
  • 经验技巧10 如何应对自己不会回答的问题
  • 经验技巧11 如何应对面试官的“激将法”语言
  • 经验技巧12 如何处理与面试官持不同观点这个问题
  • 经验技巧13 什么是职场暗语

面试真题篇
  • 真题详解1 某知名互联网下载服务提供商软件工程师笔试题
  • 真题详解2 某知名社交平台软件工程师笔试题
  • 真题详解3 某知名安全软件服务提供商软件工程师笔试题
  • 真题详解4 某知名互联网金融企业软件工程师笔试题
  • 真题详解5 某知名搜索引擎提供商软件工程师笔试题
  • 真题详解6 某初创公司软件工程师笔试题
  • 真题详解7 某知名游戏软件开发公司软件工程师笔试题
  • 真题详解8 某知名电子商务公司软件工程师笔试题
  • 真题详解9 某顶级生活消费类网站软件工程师笔试题
  • 真题详解10 某知名门户网站软件工程师笔试题
  • 真题详解11 某知名互联网金融企业软件工程师笔试题
  • 真题详解12 国内某知名网络设备提供商软件工程师笔试题
  • 真题详解13 国内某顶级手机制造商软件工程师笔试题
  • 真题详解14 某顶级大数据综合服务提供商软件工程师笔试题
  • 真题详解15 某著名社交类上市公司软件工程师笔试题
  • 真题详解16 某知名互联网公司软件工程师笔试题
  • 真题详解17 某知名网络安全公司校园招聘技术类笔试题
  • 真题详解18 某知名互联网游戏公司校园招聘运维开发岗笔试题

资料整理不易,点个关注再走吧

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

知名门户网站软件工程师笔试题

  • 真题详解11 某知名互联网金融企业软件工程师笔试题
  • 真题详解12 国内某知名网络设备提供商软件工程师笔试题
  • 真题详解13 国内某顶级手机制造商软件工程师笔试题
  • 真题详解14 某顶级大数据综合服务提供商软件工程师笔试题
  • 真题详解15 某著名社交类上市公司软件工程师笔试题
  • 真题详解16 某知名互联网公司软件工程师笔试题
  • 真题详解17 某知名网络安全公司校园招聘技术类笔试题
  • 真题详解18 某知名互联网游戏公司校园招聘运维开发岗笔试题

[外链图片转存中…(img-zSiMJNc0-1713631195369)]

资料整理不易,点个关注再走吧

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-845ueNzU-1713631195370)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 27
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值