ホームページ  >  記事  >  データベース  >  把字符串abcdef旋转2位得到字符串cdefab

把字符串abcdef旋转2位得到字符串cdefab

WBOY
WBOYオリジナル
2016-06-07 15:43:021573ブラウズ

public class RightShift { public static void main(String args[]) { char[] c = { 'a', 'b', 'c', 'd', 'e' }; for (int i = 0; i c.length; i) { System.out.print(c[i]); } for (int i = 0; i 2; i) { char temp = c[0]; for (int j = 0; j c.length -

public class RightShift {

 public static void main(String args[]) {

  char[] c = { 'a', 'b', 'c', 'd', 'e' };

  for (int i = 0; i    System.out.print(c[i]);
  }

  for (int i = 0; i    char temp = c[0];
   for (int j = 0; j     c[j] = c[j + 1];
   }
   c[c.length - 1] = temp;
  }
  System.out.println();
  for (int i = 0; i    System.out.print(c[i]);
  }
 }

}

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。