当前位置:网站首页>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,毕竟很多东西如果不经常用的话慢慢就忘记了,就比如我
边栏推荐
- Sweet alert
- Thread,Runnable,ExecutorService线程池控制下线程量
- A Practical Guide to Building OWL Ontologies using Protege4 and CO-ODE Tools - Version 1.3 (7.4 Annotation Properties - Annotation Properties)
- 8. Recursively traverse and delete cases
- GBase数据库中,源为 oracle 报出“ORA-01000:超出打开游标最大数”
- 7.Collections工具类
- Go-控制语句那些事
- 5.转换流
- 全网最全的软件测试基础知识整理(新手入门必学)
- What does the test plan include?What is the purpose and meaning?
猜你喜欢
随机推荐
黑盒测试常见错误类型说明及解决方法有哪些?
5.Set接口与实现类
关于SQL的SELECT查询语句的一般格式的描述2021-05-19
软件测试面试题目:请你列举几个物品的测试方法怎么说?
Source GBase database, oracle quote "ORA - 01000: beyond the shop open the cursor"
try catch 对性能影响
5.转换流
接口测试的基础流程和用例设计方法你知道吗?
LPP代码及其注释
Go-指针的那些事
列表
[Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)
BigDecimal用法常用操作记录
Ontology Development Diary 01-Jena Configuration Environment Variables
QT sets the icon of the exe executable
Summary of steps and methods for installing and uninstalling test cases that you must read
可以写进简历的软件测试项目实战经验(包含电商、银行、app等)
3. Coding method
手机APP测试流程规范和方法你知道多少?
归并排序





