5.23文字列反転の例
1134 ワード
/*
*
* : ”abc”
* :”cba”
*
* :
* A:
* B:
* C: ,
* a:length() charAt()
* b:
* D:
* E:
*/
public class StringTest {
public static void main(String[] args) {
//
Scanner sc = new Scanner(System.in);
System.out.println(" :");
String line = sc.nextLine();
/*
//
String result = "";
//
char[] chs = line.toCharArray();
// ,
for (int x = chs.length - 1; x >= 0; x--) {
//
result += chs[x];
}
//
System.out.println(" :" + result);
*/
//
String s = myReverse(line);
System.out.println(" :" + s);
sc.close();
}
/*
* : :String :String
*/
public static String myReverse(String s) {
//
String result = "";
//
char[] chs = s.toCharArray();
// ,
for (int x = chs.length - 1; x >= 0; x--) {
//
result += chs[x];
}
return result;
}
}