將字串【"Hello world" 】 倒序結果為【"world Hello " 】
String arr= "Hello world";
// 每個空格處進行分割
String s[] = arr.split(" ");
// 通過迴圈輸出陣列內容
for(int i=0; i<s.length; i++){
System.out.printf("s內容為"+ s[i] +"\n");
}
// 實現倒序轉換
for(int j=0; j<s.length; j++){
String temp = s[j];
s[j] = s[s.length
s[s.length-1] = temp;
}
// 使用Array類輸出陣列內容
System.out.printf("s倒序後的內容為"+ Arrays.toString(s) +"\n");
// 陣列轉換成字串
String ss = org.apache.commons.lang.StringUtils.join(s," ");
System.out.printf("SS 內容為" + ss);
相關推薦
將字串【"Hello world" 】 倒序結果為【"world Hello " 】
public void exchange(){ String arr= "Hello world"; // 每個空格處進行分割 String s[] = arr.split(" "); // 通過迴圈輸出陣列內容 for(int i=0; i<s.length; i++){
Pascal【入門】倒序輸出一個四位整數
題目描述: 任意輸入一個四位數,顛倒後輸出。 輸入: 輸入一行,只有一個整數x。(1000<x<9999) 輸出: 輸出只有一行,為一個整數。 樣例輸入: 1234 樣例輸出
【11.2校內測試】【狀壓】【矩陣字首和】【樹狀陣列逆序對(題意轉換)】
Solution 簽到水題,直接狀壓列舉所有情況算出答案即可。 Code #include<bits/stdc++.h> #define LL long long using namespace std; inline LL read() { LL x =
java 編寫一個程式實現字串大小寫的轉換並倒序輸出
package cn; public class Test01 { public static void main(String[] args) { String str= "HelloWorld"; char[] ch = str.toCharArray();
將一個英文句子的單詞倒序輸出到另一個檔案,單詞內容不倒序
#include<stdio.h> #include<string.h> void reverse(char* buf,char* b) { int i=0; int j,k=0; for(i=strlen
編寫一個程式實現字串“HelloWorld”大小寫轉換並倒序輸出。
使用for迴圈,將字串“HelloWorld”從最後一個字元開始遍歷,當遍歷的字元如果是大寫字元時,需要轉換成小寫;反之則轉換成大寫。定義一個StringBuffer物件,呼叫append()方法依次新增遍歷的字元,最後呼叫StringBuffer物件的toString()
實現字串“HelloWorld”大小寫轉換並倒序輸出
提示:使用for迴圈,將字串“HelloWorld”從最後一個字元開始遍歷,當遍歷的字元如果是大寫字元時,需要轉換成小寫;反之則轉換成大寫。定義一個StringBuffer物件,呼叫append()方法依次新增遍歷的字元,最後呼叫StringBuffer物件的toString
【我是程式猿,我為自己代言】 不要讓任何事情成為你不去學習的理由。
博主個人很喜歡網購,推薦各位加微信 annalego 她可以幫大家免費找淘寶天貓內部優惠券,不管你在淘寶天貓上看到的任何商品都可以,一年省個幾千上萬塊沒問題(前提是你喜歡網購-_-!)。 博主前些天在某天貓旗艦店看上件夾克售價289元,任何人直接通過搜尋進入到這
【SQL Server 2012】按倒序存儲“分組統計”結果的臨時表到新建表
lec 訪問 mage 臨時表 聚合函數 ren 查詢 多個 相關 程序預先說明: 本文訪問的數據庫是基於存有RDF三元組的開源數據庫Localyago修改的庫,其中只有一個表,表中有五個屬性:主語subject、謂語predict、賓語object、主語的編號subid,
【演算法】將字串中的空格替換成指定字串
題目: 字串中的空格替換成指定字串,如%20。 給定一個字串,內部有空格,請用最少的時間複雜度、空間複雜度,將空格替換為%20 示例: 輸入: This is a test string 輸出: This%20is%20a%20test%20%string 思路: 只建立
用指標編寫程式將輸入的字串倒序輸出
#include<iostream> #include<string.h> using namespace std; int main() { char a[20]; int i; char *p; p=a; cout<<"輸入一個字串"<<
【c語言】將一個數的二進位制序列逆序,然後輸出逆序之後的二進位制序,所對應的數
<pre name="code" class="cpp">// 將一個數的二進位制序列逆序,然後輸出逆序之後的二進位制序,所對應的數 #include <stdio.h> // 從原數拿出最低位,放到mid中,mid左移,原數右移 int r
【C語言】將二進位制數逆序輸出。比如6為000...0110,逆序後為0110...000
//將二進位制數逆序輸出。比如6為000...0110,逆序後為0110...000 #include <stdio.h> unsigned int reverse_bit(int num
【C++從入門到熟練練習題】000 VS2015新建程式及輸出Hello World
一、前言 大學很多計算機相關專業的基礎課都會有C++,C++是比較經典的程式語言,程式語言一定不是看出來的,而是敲程式碼敲出來的。所以會給大家不定期分享一些C++練習題。在下一次的練習題中,會給出這次的答案,希望大家能夠喜歡,也希望大家能夠多提意見,一起學習。 作為第一篇部落格,因為有很
【Qt學習筆記之一】初識Qt、環境搭建及hello world的實現
初識Qt Qt,簡單來說就是一個跨平臺的C++圖形使用者介面應用程式開發框架。因此,相比很多開發框架,Qt的特點更多體現在GUI程式的開發上。我們平時使用的QQ(介面越來越花哨)、微信、瀏覽器等等,只要是你作為使用者,能夠看到一個介面去操作,那麼它就可以
【spring MVC】新手從零新建第一個hello world專案
說明 本文適合一個沒有搭建過spring MVC專案的新手(甚至沒怎麼參與過java相關專案的新手)參閱! 這也是arvik參考網路文章學習spring MVC搭建的一個筆記 軟體安裝 安裝jdk 開啟windows命令列視窗執行命令檢查
編寫程式,迴圈接收使用者從鍵盤輸入多個字串,直到輸入“ end”時迴圈結束,並將所有 已輸入的字串按字典順序倒序列印。
package com.heima.test; import java.util.Comparator; import java.util.Scanner; import java.util.Tree
【演算法】【將字串轉換成int】
之前還使用過遞迴來計算,不過現在已經記不起來了 #include <stdio.h> #include <error.h> #include <math.h> #define ERROR -22 #define DEBUG 0
【C/C++】將字串按空格逆置
一、題目要求 有一個字元陣列的內容為:"student a am i",請你將陣列的內容改為"i am a student". 要求: 不能使用庫函式。只能開闢有限個空間(空間個數和字串的長度無關)。 二、題目分析 初級理解: 乍一看,這是一個字串逆置 可是真的有這麼簡單嗎
【筆記】C++入門學習第一課(Hello World!)
ubun names 鏈接 簡介 sudo ont 大小 ostream 編寫 學習環境:Ubuntu14.04、gcc version 4.8.4 、Notepad++ 在Linux下安裝g++命令:sudo apt-get install g++(需要輸入登錄密碼獲得