java - reverse()
来源:趣味经验馆 2.75W
<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
java reverse() 是什么?让我们一起来了解一下吧!
java reverse() 是java中的一种函数,用来倒置字符串。reverse函数可倒置字符串string里的每个字符的位置。比如原先字符串里面的初始值是987654,通过使用reverse函数便可以倒置为456789。
一.使用reverse函数反转string
string N;cin>>N;reverse(N.begin(), N.end());
二.使用reverse函数反转字符数组
char s[101];cin.getline(s,sizeof(s));int m=strlen(s);reverse(s,s+m);puts(s);
三.使用reverse函数反转整型数组
int a[100];reverse(a,a+10); //第二个参数是数组最后一个元素的下一个地址
实战演练,具体步骤如下:
// 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);} }
以上就是小编今天的分享了,希望可以帮助到大家。