JavaDay7(下)
2024-10-08 06:49:10
问题1描述
编写一个方法,返回一个double类型二维数组,数组中的元素通过解析字符串参数获得。
代码实现:
public class ArrayParser {
public static void main(String[] args) {
double[][] d;
String s = "1,2;3,4,5;6,7,8";
String[] sFirst = s.split(";");
d = new double[sFirst.length][];
for (int i = 0; i < sFirst.length; i++) {
String[] sSecond = sFirst[i].split(",");
d[i] = new double[sSecond.length];
for (int j = 0; j < sSecond.length; j++) {
d[i][j] = Double.parseDouble(sSecond[j]);
}
}
for (int i = 0; i < d.length; i++) {
for (int j = 0; j < d[i].length; j++) {
System.out.println(d[i][j] + " ");
}
System.out.println();
}
}
}
问题2描述
编写一个程序,在命令行中以树状结构展现特定的文件夹及其子文件(夹)。
代码实现
import java.io.*;
public class FindFile {
public static void main(String[] args) {
File file = new File("F:/github/JavaFile/JavaBasic");
System.out.println(file.getName());
int level = 0;
getChild(file, level);
}
public static void getChild(File file, int level) {
String space = "";
for (int i = 0; i <= level; i++) {
space += " ";
}
File[] childfile = file.listFiles();
for (int i = 0; i < childfile.length; i++) {
System.out.println(space + childfile[i].getName());
if (childfile[i].isDirectory()) {
getChild(childfile[i], level+1);
}
}
}
}
最新文章
- 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具
- WPF 如何画一颗心
- centos7精简版(minimal)killall: command not found
- [NOIP2010] 提高组 洛谷P1514 引水入城
- c# 定时执行python脚本
- 未能加载文件或程序集“SQLDAL”或它的某一个依赖项。系统找不到指定的文件
- javascript设计模式-外观模式
- 50道经典的JAVA编程题(46-50)
- js难点之闭包理解
- js面向对象的五种写法
- QtQml 应用程序的性能考虑与建议(来自小V的翻译)
- posix信号量(sem_t)
- linux下大于2T的硬盘格式化方法
- windows环境下mysql主从配置
- java去重(1通过迭代器,2直接赋值)
- Pytorch中的自动求导函数backward()所需参数含义
- hibernate框架学习第四天:关联关系、外键、级联等
- 基于react的记账簿开发
- rabbitmq系列五 之主题交换机
- BZOJ1211:[HNOI2004]树的计数(组合数学,Prufer)
热门文章
- 手把手教你Dubbo与SpringBoot常用两种方式整合
- Python Special Methods - 特殊方法
- 如何开始阅读ASP.NET Core源代码
- ORB-SLAM2 论文&;代码学习 —— 概览
- Params:params 关键字可以指定在参数数目可变处采用参数的方法参数。
- LVS服务原理以及搭建
- iptables之路由网关共享上网/端口映射
- NOIP2012-------跳石头(C语言)
- C# bubble sort,selection sort,insertion sort
- php利用七牛云的对象存储完成图片上传-高效管理图片