题解 | #数组倒转#
数组倒转
https://www.nowcoder.com/practice/3a90caee736a45e1ad70b1d4105dec5f
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { int[] arr = new int[6]; Scanner sc = new Scanner(System.in); for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); } System.out.println(Arrays.toString(arr)); //write your code here...... int left=0; int right=arr.length-1; while(left<right){ int temp=arr[left]; arr[left]=arr[right]; arr[right]=temp; left++; right--; } System.out.println(Arrays.toString(arr)); } }
java相关 文章被收录于专栏
java刷题,或许会有其他方面