java问题。输出结果是0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 左对齐!最好用多维数组。
012345678910111213141516171819每五个是一组,左对齐。晚上十二点之前告诉答案的多加悬赏二十分...
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
每五个是一组,左对齐。晚上十二点之前告诉答案的多加悬赏二十分 展开
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
每五个是一组,左对齐。晚上十二点之前告诉答案的多加悬赏二十分 展开
展开全部
public class Change{
public static void main(String[] args){
int Co=30; //排序到多少位?
int[][] Arr=new int[5][]; //定义不规则数组
int integer=0;//用来计数的
for (int i = 0; i < 5; i++) {
Arr[i] =new int[Co/5];
for (int j = 0; j < Co/5; j++) {
Arr[i][j]=integer++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < Co/5; j++) {
System.out.print(","+Arr[i][j]);
}
System.out.println();
}
}
}
效果
,0,1,2,3,4,5
,6,7,8,9,10,11
,12,13,14,15,16,17
,18,19,20,21,22,23
,24,25,26,27,28,29
写错了,,,特来更正
=========================================================================
public class Change{
public static void main(String[] args){
int[][] Arr=new int[5][];
int Co=30;
int integer=0;
for (int i = 0; i < 5; i++) {
Arr[i] =new int[Co/5];
}
for (int i = 0; i < Co/5; i++) {
for (int j = 0; j < 5; j++) {
Arr[j][i]=integer++;
}
}
for (int i = 0; i < Co/5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(","+Arr[j][i]);
}
System.out.println();
}
}
}
效果
,0,1,2,3,4
,5,6,7,8,9
,10,11,12,13,14
,15,16,17,18,19
,20,21,22,23,24
,25,26,27,28,29
public static void main(String[] args){
int Co=30; //排序到多少位?
int[][] Arr=new int[5][]; //定义不规则数组
int integer=0;//用来计数的
for (int i = 0; i < 5; i++) {
Arr[i] =new int[Co/5];
for (int j = 0; j < Co/5; j++) {
Arr[i][j]=integer++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < Co/5; j++) {
System.out.print(","+Arr[i][j]);
}
System.out.println();
}
}
}
效果
,0,1,2,3,4,5
,6,7,8,9,10,11
,12,13,14,15,16,17
,18,19,20,21,22,23
,24,25,26,27,28,29
写错了,,,特来更正
=========================================================================
public class Change{
public static void main(String[] args){
int[][] Arr=new int[5][];
int Co=30;
int integer=0;
for (int i = 0; i < 5; i++) {
Arr[i] =new int[Co/5];
}
for (int i = 0; i < Co/5; i++) {
for (int j = 0; j < 5; j++) {
Arr[j][i]=integer++;
}
}
for (int i = 0; i < Co/5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(","+Arr[j][i]);
}
System.out.println();
}
}
}
效果
,0,1,2,3,4
,5,6,7,8,9
,10,11,12,13,14
,15,16,17,18,19
,20,21,22,23,24
,25,26,27,28,29
追问
没有后面的25 26 27 28 29
而且你能用多维数组做吗?你这个我没有学到呢,看不懂。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
int[][] a = new int[4][5];
int[] b = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int k = b.length - 1;
for(int i = a.length - 1; i >= 0; i--) {
for(int j = a[i].length - 1; j >= 0; j--) {
a[i][j] = b[k];
k--;
}
}
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j]+""+'\t'); // '\t'这个转义符就是左对齐的作用;
}
System.out.println();
}
}
}
int[][] a = new int[4][5];
int[] b = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int k = b.length - 1;
for(int i = a.length - 1; i >= 0; i--) {
for(int j = a[i].length - 1; j >= 0; j--) {
a[i][j] = b[k];
k--;
}
}
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j]+""+'\t'); // '\t'这个转义符就是左对齐的作用;
}
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/**和前几楼的有点不一样,看看这个符合要求不,输出格式也可以用System.out.printf(..)*/
public class Test_1 {
/**
* @param args
*/
public static void main(String[] args) {
int i, j, k = 0;
int[][] a = new int[4][5];
for (i = 0; i < 4; i++) {
for (j = 0; j < 5; j++, k++) {
a[i][j] = k;
}
}
for (i = 0; i < 4; i++) {
System.out.println();
for (j = 0; j < 5; j++) {
System.out.print(" " + a[i][j]);
}
}
}
}
public class Test_1 {
/**
* @param args
*/
public static void main(String[] args) {
int i, j, k = 0;
int[][] a = new int[4][5];
for (i = 0; i < 4; i++) {
for (j = 0; j < 5; j++, k++) {
a[i][j] = k;
}
}
for (i = 0; i < 4; i++) {
System.out.println();
for (j = 0; j < 5; j++) {
System.out.print(" " + a[i][j]);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class test {
public static void main(String[] args) {
int[] lit = new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
for (int i = 0 ; i < lit.length ; i++) {
System.out.print(i+" ");
if((i+1)%5 == 0) System.out.println();
}
}
}
public static void main(String[] args) {
int[] lit = new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
for (int i = 0 ; i < lit.length ; i++) {
System.out.print(i+" ");
if((i+1)%5 == 0) System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Test {
public static void main(String[] args) {
int i, j;
int[][] arr = new int[4][5];
for(i=0; i<4; i++){
for(j=0; j<5; j++){
arr[i][j] = i * 5 + j;
}
}
for(i=0; i<4; i++){
for(j=0; j<5; j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
public static void main(String[] args) {
int i, j;
int[][] arr = new int[4][5];
for(i=0; i<4; i++){
for(j=0; j<5; j++){
arr[i][j] = i * 5 + j;
}
}
for(i=0; i<4; i++){
for(j=0; j<5; j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询