恋日记 2022-03-19 15:25 采纳率: 33.3%
浏览 29
已结题

关于#java#的问题,如何解决?(开发工具-eclipse)

img


就是要打印原数组也要打印互换的二维数组
运行结果:
123
456
789
147
258
369

  • 写回答

1条回答 默认 最新

  • 我要学好编程 2022-03-19 17:07
    关注
    
    import java.util.Scanner;
    
    public class demo01 {
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入二维数组的列数");
            int n1=sc.nextInt();
            System.out.println("请输入二维数组的行数");
            int n2=sc.nextInt();
            //定义一个二维数组
            //原数组
            int [][]array1=new int[n1][n2];
            //行列互掉的二维数组
            int [][]array2=new int[n2][n1];
            System.out.println("请向数组中输入元素,从左向右,从上到下");
            for (int i = 0; i < n1; i++) {
                System.out.println("请输入第"+(i+1)+"行数据");
                for (int j = 0; j < n2; j++) {
                    int x= sc.nextInt();
                    array1[i][j]=x;
                    array2[j][i]=x;
                }
            }
            //原来的二维数组
            System.out.println("原来的二维数组是:");
            for (int i = 0; i < n1; i++) {
                for (int j = 0; j < n2; j++) {
                    System.out.print(array1[i][j]+" ");
                }
                System.out.println("");
            }
            //置换后的二维数组
            System.out.println("置换后的二维数组为:");
            for (int i = 0; i < n1; i++) {
                for (int j = 0; j < n2; j++) {
                    System.out.print(array2[i][j]+" ");
                }
                System.out.println("");
            }
        }
    }
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    1人已打赏

报告相同问题?

问题事件

  • 系统已结题 3月27日
  • 已采纳回答 3月19日
  • 修改了问题 3月19日
  • 创建了问题 3月19日

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装