sdut java lab6主观题

简介: sdut java lab6主观题

8-1 SDUT-JAVA-TestPassArray

分数 1

全屏浏览

作者 马新娟

单位 山东理工大学

This is an array, which name is a.Arayy a has 2 elements,a[0] is 1 and a[1] 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.

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();
 
}
 
}


目录
相关文章
|
Java
SDUT JAVA lab3.9
SDUT JAVA lab3.9
126 2
|
Java
sdut java lab 7.1(法二好理解)
sdut java lab 7.1(法二好理解)
120 1
|
Java
SDUT Java lab6
SDUT Java lab6
88 0
|
Java
sdut java lab7单选
sdut java lab7单选
129 0
|
人工智能 Java
sdut java lab5
sdut java lab5
103 0
|
Java
sdut java lab7.2(法二)
sdut java lab7.2(法二)
104 0
|
存储 Java 索引
sdut java lab 7.6
sdut java lab 7.6
157 0
|
存储 Java
SDUT java lab7.4
SDUT java lab7.4
95 0
|
3月前
|
JSON 网络协议 安全
【Java】(10)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
220 1
|
3月前
|
JSON 网络协议 安全
【Java基础】(1)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
240 1