
java reverse()?是什么?讓我們一起來了解一下吧!
java reverse()?是java中的一種函數(shù),用來倒置字符串。reverse函數(shù)可倒置字符串string里的每個字符的位置。比如原先字符串里面的初始值是987654,通過使用reverse函數(shù)便可以倒置為456789。

一.使用reverse函數(shù)反轉(zhuǎn)string
string?N; cin>>N; reverse(N.begin(),?N.end());
二.使用reverse函數(shù)反轉(zhuǎn)字符數(shù)組
char?s[101]; cin.getline(s,sizeof(s)); int?m=strlen(s); reverse(s,s+m); puts(s);
三.使用reverse函數(shù)反轉(zhuǎn)整型數(shù)組
int?a[100]; reverse(a,a+10);?????????//第二個參數(shù)是數(shù)組最后一個元素的下一個地址
實戰(zhàn)演練,具體步驟如下:
//?Java?program?to?demonstrate?the?example
//?of?reverse(int?value)?method?of?Integer?class
?
public?class?ReverseOfIntegerClass?{
????public?static?void?main(String[]?args)?{
????????int?value?=?1296;
?
????????//?Display?value
????????System.out.println("value:"?+?value);
?
????????//?It?returns?the?string?representation?of?the?given?unsigned
????????//?integer?value?denoted?by?the?argument?in?binary?by?calling
????????//?Integer.toBinaryString(value)
????????System.out.println("Integer.toBinaryString(value):?"?+?Integer.toBinaryString(value));
?
????????//?It?returns?the?value?generated?by?reversing?the
????????//?order?of?the?bits?in?the?given?argument?value
????????//?by?calling?Integer.reverse(value)
????????System.out.println("Integer.reverse(value):?"?+?Integer.reverse(value));
????}
}package?test;
?
public?class?Main96?{
?
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
??StringBuffer?str=new?StringBuffer("ABCD");
??str.reverse();
????System.out.print(str);
}
?
}?以上就是小編今天的分享了,希望可以幫助到大家。
