Skip to content

Instantly share code, notes, and snippets.

@peter279k peter279k/JPA05.java
Created May 24, 2017

Embed
What would you like to do?
TQC+ JAVA
public class JPA05 {
public static void main(String[] argv) {
String[] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
System.out.print("反轉陣列資料之前: ");
String str = "";
for(int index=0;index<data.length;index++) {
if(index != data.length-1) {
str += data[index] + " ";
} else {
str += data[index];
}
}
System.out.println(str);
reverse(data);
str = "";
System.out.print("反轉陣列資料之後: ");
for(int index=0;index<data.length;index++) {
if(index != data.length-1) {
str += data[index] + " ";
} else {
str += data[index];
}
}
System.out.println(str);
}
public static void reverse(String []data) {
for(int index=0;index<data.length/2;index++) {
String temp = data[index];
data[index] = data[data.length-index-1];
data[data.length-index-1] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.