
java作业,求大神..在线等
作业是输出一个二维表格12673581349121410111516找一下规律求大神啊,今晚要交不会做...求程序......
作业是输出一个二维表格
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
找一下规律
求大神啊,今晚要交
不会做...求程序... 展开
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
找一下规律
求大神啊,今晚要交
不会做...求程序... 展开
3个回答
展开全部
import java.util.Arrays;
public class PrintTable {
public static void main(String[] args) {
int[][] array = new int[4][4];
int count = 1;
for (int i = 0; i < 2 * array.length - 1; i++) {
if (i % 2 == 1) {
for (int row = 0; row < i + 1; row++) {
int column = i - row;
if (row < array.length && column < array.length) {
array[row][column] = count++;
}
}
} else {
for (int row = i; row >=0; row--) {
int column = i - row;
if (row < array.length && column < array.length) {
array[row][column] = count++;
}
}
}
}
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + "\t");
}
System.out.println();
}
}
}
刚手写的,亲测没问题,你先看看,看不懂再问。
public class PrintTable {
public static void main(String[] args) {
int[][] array = new int[4][4];
int count = 1;
for (int i = 0; i < 2 * array.length - 1; i++) {
if (i % 2 == 1) {
for (int row = 0; row < i + 1; row++) {
int column = i - row;
if (row < array.length && column < array.length) {
array[row][column] = count++;
}
}
} else {
for (int row = i; row >=0; row--) {
int column = i - row;
if (row < array.length && column < array.length) {
array[row][column] = count++;
}
}
}
}
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + "\t");
}
System.out.println();
}
}
}
刚手写的,亲测没问题,你先看看,看不懂再问。
展开全部
这个太简单了,代码骚等 ,我晕,还真不太好做,想了很久
package mythread;
public class ArrayTest {
public static void main(String[] args){
int a=10;
int[][] tem=new int[a][a];
int count=0;
for(int i=0;i<a*2-1;i++){
if(i<a){
for(int j=0;j<=i;j++){
count++;
if(i%2==0){
tem[i-j][j]=count;
}else{
tem[j][i-j]=count;
}
}
}else{
for(int j=2*a-i-1;j>0;j--){
count++;
if(i%2==0){
tem[j+(i%a)][a-j]=count;
}else{
tem[a-j][j+(i%a)]=count;
}
}
}
}
for(int i=0;i<a;i++){
for(int j=0;j<a;j++){
System.out.print(tem[i][j]+",");
if(tem[i][j]<10){
System.out.print(" ");
}
}
System.out.println();
}
}
}
最近变傻了,想了很久
package mythread;
public class ArrayTest {
public static void main(String[] args){
int a=10;
int[][] tem=new int[a][a];
int count=0;
for(int i=0;i<a*2-1;i++){
if(i<a){
for(int j=0;j<=i;j++){
count++;
if(i%2==0){
tem[i-j][j]=count;
}else{
tem[j][i-j]=count;
}
}
}else{
for(int j=2*a-i-1;j>0;j--){
count++;
if(i%2==0){
tem[j+(i%a)][a-j]=count;
}else{
tem[a-j][j+(i%a)]=count;
}
}
}
}
for(int i=0;i<a;i++){
for(int j=0;j<a;j++){
System.out.print(tem[i][j]+",");
if(tem[i][j]<10){
System.out.print(" ");
}
}
System.out.println();
}
}
}
最近变傻了,想了很久
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1到5到9每次加2的平方,
追问
能帮忙把程序写下吗..不会做
追答
已经有人告诉你了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询