Created
May 24, 2017 18:56
-
-
Save peter279k/54ebd4fb9cfc23e34ac5bfd12664dc77 to your computer and use it in GitHub Desktop.
TQC+ JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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