實例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import java.util.Scanner; /** * Created by Admin on 2017/3/27. */ public class test02 { public static String RightUpper(String str){ char [] S=str.toCharArray(); int count= 0 ; for ( int i= 0 ;i<str.length();i++) { if (Character.isLowerCase(S[i])){ char temp=S[i]; for ( int j=i;j>count;j--){ //小寫字母移動到count后一格 S[j]=S[j- 1 ]; //count處的值賦予給count后一格處(即j處) } S[count]=temp; //count賦i處的小寫字母 count++; //完成一處小寫字母左移動后,count加1; } } // System.out.println("向左移動了"+count+"次小寫字母"); return String.copyValueOf(S); } public static void main(String[] args) { Scanner scanner= new Scanner(System.in); while (scanner.hasNext()){ String str=scanner.nextLine(); System.out.println(RightUpper(str)); } } } |
以上這篇java字符串的大寫字母右移實現方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。