新手,问一个比较菜的问题?

bj518 2007-09-14 07:41:44
//1、 写一个矩形的类,打印两个矩形,3*4,5*7.
public class dayin {
public static void main(String[] args){
int[][] a = new int[3][4];
for(int i=0;i<=a.length;i++){
for(int j=0;j<=a[0].length;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
不知道哪里错了?一期刚结业,到二期学Java 感到不太适应,可能是一期的基础不太好,希望大家多多指教!
...全文
178 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xue110083 2007-09-15
  • 打赏
  • 举报
回复
到此一游!
dragon_up 2007-09-14
  • 打赏
  • 举报
回复
public class dayin {
public static void main(String[] args){
int[][] a = new int[3][4];
for(int i=0;i<a.length;i++){
for(int j=0;j<a[0].length;j++){
System.out.print('*');
}
System.out.println();
}
}

搞定~~
miaoenhuai 2007-09-14
  • 打赏
  • 举报
回复
public class dayin {
public static void main(String[] args){
int[][] a = new int[3][4];
for(int i=0;i<a.length;i++){
for(int j=0;j<a[0].length;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
把等号去掉就行了,否则产生数组下标越界的错误
steven138 2007-09-14
  • 打赏
  • 举报
回复
如果只想效果是这样的话:
****
****
****
根本不用什么数组,这样就行了
class dayin{
public static void main(String[] args){
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
System.out.print("*");
System.out.println();
}
}
}
zephyr_cc 2007-09-14
  • 打赏
  • 举报
回复
用char
要不你在打印时候加上(char)
bj518 2007-09-14
  • 打赏
  • 举报
回复
好象不行,我执行的结果是:

42 42 42 42
42 42 42 42
42 42 42 42
zephyr_cc 2007-09-14
  • 打赏
  • 举报
回复
public class dayin {
public static void main(String[] args) {
char[][] a = new char[3][4];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
a[i][j] = '*';
System.out.print(a[i][j]);
}
System.out.println();
}
}
}
bj518 2007-09-14
  • 打赏
  • 举报
回复
请问如何把这道题变成

****
****
****

这样?
zephyr_cc 2007-09-14
  • 打赏
  • 举报
回复
public class dayin {
public static void main(String[] args) {
int[][] a = new int[3][4];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧