Java数组逆序存储

package review01;

import java.util.Arrays;

public class review01 {
    public static void main(String[] args) {
    method();
    }

    private static void method() {
    // 数组逆序存储
    int[] arr = { 2, 0, 1, 6, 1, 2, 0, 7, 2, 0, 1, 2, 3, 3 };
    for (int s = 0, e = arr.length - 1; s < e; s++, e--) {
        int t = arr[s];
        arr[s] = arr[e];
        arr[e] = t;
    }
    System.out.println(Arrays.toString(arr));
    }
}
时间: 2024-10-05 15:36:56

Java数组逆序存储的相关文章

Java数组逆序排列

public class Test4 { public static void main(String[] args) { //数组的逆序 {12,69,852,25,89,588} int[] arr = {12,69,852,25,89,588}; reverse(arr); printArray(arr);} public static void reverse(int[] arr){ for(int min =0,max=arr.length-1;min<max;min++,max--)

字符串数组逆序

1 import java.util.Arrays; 2 import java.util.Comparator; 3 4 class ResStrSort{ 5 public static void main(String[] args) { 6 String strs[] = {"dog","cat","horse","cow"}; 7 System.out.println("Initial order: &qu

数组逆序=全局内存版 VS 共享内存版

全局内存版 1 #include <stdio.h> 2 #include <assert.h> 3 #include "cuda.h" 4 #include "cuda_runtime.h" 5 #include "device_launch_parameters.h" 6 //检查CUDA运行时是否有错误 7 void checkCUDAError(const char* msg); 8 // Part3: 在全局内存

嵌入式 linux和c 指针顺序和逆序存储

顺序存储 #include<stdio.h>int main(){ char a[10]="1234567890"; char b[9]; char *p=a; char *q=b; int i=10; while(i--) *q++=*p++; printf("%s\n",b); return 0;} 逆序存储 #include<stdio.h>int main(){ char a[10]="1234567890"; c

java数组降序排序之冒泡排序

1 import java.util.Arrays;//必须加载 2 class Demo{ 3 public static void main(String []args){ 4 int[] arr={3,54,456,342,2798,15,78,56,95,5678,9,5}; 5 System.out.println(Arrays.toString(arr));//java打印数组,排序前[3, 54, 456, 342, 2798, 15, 78, 56, 95, 5678, 9, 5

[LeetCode]2. Add Two Numbers用链表逆序存储的两个数相加

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 ->

lua学习笔记15:table数组逆序

数组的逆序,只能用于数组,不能用于哈希表 function reverseTable(tab) local tmp = {} for i = 1, #tab do local key = #tab tmp[i] = table.remove(tab) end return tmp end // 示例 local t = {"one", "two", "three"} for k, v in pairs(t) do print(k, v) end

C数组逆序

一.标准交换模式 /**** *标准交换模式 *实现数组的逆序,原理就是数组的首尾元素进行交换 ***/ #define N 5; int main(){ int array[N] = {15,20,25,30,35} int temp; //声明临时变量 int i; for(i = 0;i<N/2;i++){ //第i个值和第N-i-1个值相交换 temp = array[i]; array[i] = array[N - i - 1]; array[N - i - 1] = temp; }

1-6-04:数组逆序重放

描述 将一个数组中的值按逆序重新存放.例如,原来的顺序为8,6,5,4,1.要求改为1,4,5,6,8. 输入 输入为两行:第一行数组中元素的个数n(1<n<100),第二行是n个整数,每两个整数之间用空格分隔. 输出 输出为一行:输出逆序后数组的整数,每两个整数之间用空格分隔. 样例输入 5 8 6 5 4 1 样例输出 1 4 5 6 8 1 #include<stdio.h> 2 int main() 3 { 4 int a[101]={0}; 5 int n; 6 scan