Heim  >  Artikel  >  Datenbank  >  把字符串abcdef旋转2位得到字符串cdefab

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

WBOY
WBOYOriginal
2016-06-07 15:43:021573Durchsuche

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]);
  }
 }

}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn