当前位置:网站首页>Arrays.toString( )打印二维数组
Arrays.toString( )打印二维数组
2022-08-09 09:29:00 【农场主er】
解释
官方API文档中toString()的传入参数是一维数组,所以要打印二维数组,需要分别将二维数组的行传入toString中。
如果二维数组是String a[ i ][ j ],要打印第一行的话需要传入a[ 0 ] .
示例
public class Cards {
private final String[] suit={
"黑桃","红桃","方块","梅花"};
private final String[] points={
"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
private String[][] cards;
//构造函数
public Cards(){
cards=new String[suit.length][points.length];
}
//创建扑克牌
public void CreatCards(){
for(int i=0;i<suit.length;i++){
for(int j=0;j<points.length;j++){
cards[i][j]=suit[i]+points[j];
}
}
}
//打印扑克牌
public void printCards() {
//增强型for循环
for (String[] each : cards) {
System.out.println(Arrays.toString(each));
}
}
}
结果
[黑桃A, 黑桃2, 黑桃3, 黑桃4, 黑桃5, 黑桃6, 黑桃7, 黑桃8, 黑桃9, 黑桃10, 黑桃J, 黑桃Q, 黑桃K]
[红桃A, 红桃2, 红桃3, 红桃4, 红桃5, 红桃6, 红桃7, 红桃8, 红桃9, 红桃10, 红桃J, 红桃Q, 红桃K]
[方块A, 方块2, 方块3, 方块4, 方块5, 方块6, 方块7, 方块8, 方块9, 方块10, 方块J, 方块Q, 方块K]
[梅花A, 梅花2, 梅花3, 梅花4, 梅花5, 梅花6, 梅花7, 梅花8, 梅花9, 梅花10, 梅花J, 梅花Q, 梅花K]
总结
可以多查查Java SE API,毕竟很多东西如果不经常用的话慢慢就忘记了,就比如我
边栏推荐
- A little experience sharing about passing the CISSP exam at one time
- How much do you know about the mobile APP testing process specifications and methods?
- 3.List接口与实现类
- 【机器学习】数据科学基础——机器学习基础实践(二)
- 在anaconda环境中配置cuda和cudnn
- 通用的测试用例编写大全(登录测试/web测试等)
- 性能测试包括哪些方面?分类及测试方法有哪些?
- Summary of steps and methods for installing and uninstalling test cases that you must read
- A Practical Guide to Building OWL Ontologies using Protege4 and CO-ODE Tools - Version 1.3 (7.4 Annotation Properties - Annotation Properties)
- 单元测试是什么?怎么写?主要测试什么?
猜你喜欢
随机推荐
接口测试的概念、目的、流程、测试方法有哪些?
本体开发日记03-理解代码
关于一次性通过CISSP考试的一点经验分享
6.Map interface and implementation class
.equals ==
日期操作比较全面得代码
Lecture 4 SVN
Cisco common basic configuration of common commands
class object property method class member
7.FileFilter interface
Ontology Development Diary 01-Jena Configuration Environment Variables
The div simulates the textarea text box, the height of the input text is adaptive, and the word count and limit are implemented
软件测试流程包括哪些内容?测试方法有哪些?
4.泛型和工具类
测试用例的原则、缺陷报告怎么写你都知道吗?
有返回值的函数
【分布式事务】
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
接口测试的基础流程和用例设计方法你知道吗?
QT sets the icon of the exe executable





