sdut java lab6主观题

8-1 SDUT-JAVA-TestPassArray

分数 1

全屏浏览

作者 马新娟

单位 山东理工大学

This is an array, which name is a.Arayy a has 2 elements,a0 is 1 and a1 is 2.

Now please write two methods,one only passes by value and the other pass array.In these two methods,the elements of a are swapped.

You should write the JAVA program to display all the values before invoking the methods and after invoking the methods.

java 复制代码
public static void main(String\[\] args) {

    int\[\] a = {1, 2};

    System.out.println("调用方法之前:");

    displayArray(a);

    swapValue(a\[0\], a\[1\]);

    System.out.println("调用仅传递值的方法之后:");

    displayArray(a);

    swapArray(a);

    System.out.println("调用传递数组的方法之后:");

    displayArray(a);

}

public static void swapValue(int x, int y) {

    int temp = x;

    x = y;

    y = temp;

}

public static void swapArray(int\[\] arr) {

    int temp = arr\[0\];

    arr\[0\] = arr\[1\];

    arr\[1\] = temp;

}

public static void displayArray(int\[\] arr) {

    for (int i = 0; i < arr.length; i++) {

        System.out.print(arr\[i\] + " ");

    }

    System.out.println();

}

}
相关推荐
用户813267933251 分钟前
Python 计算盘中 VWAP:为什么 1 分钟 K 线是量化工程中的高性价比选择
后端·算法·github
君顾14 分钟前
AI智能商城实战指南:从架构设计到部署落地的完整技术方案
java·开发语言·多商户
高频因子挖掘机5 分钟前
Python批量获取1000只ETF 5分钟K线:从分页到吞吐量优化的QuantDash实践
后端·算法·github
Rain的Java大神之路6 分钟前
SkyWalking从0-1部署成功实战
java·后端·架构
就叫飞六吧7 分钟前
Spring 动态注册与移除 Bean 科普
java·后端·spring
IMPYLH10 分钟前
HTML 的 <legend> 元素
java·前端·html
运行时异常13 分钟前
WMS 仓储系统集成 AI Agent 实战】第 1 讲:从零搭建开发环境——pgvector 装不上、模型选错、依赖冲突,一天踩完三个大坑
java
夕除13 分钟前
redis--008
java·jvm·数据库
wear工程师17 分钟前
线程池队列满了会怎样?从拒绝策略看懂 ThreadPoolExecutor 的扩容顺序
java
晓晓_za89866818 分钟前
多租户 GEO 优化系统源码架构:权限隔离与数据分离实现
java·tcp/ip·spring·缓存·微服务·架构