using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 堆和栈 { class Program { static void Main(string[] args) { #region 引用类型 // s : 对象的引用[存储在栈中] //new Student() [对象存储在堆中] Student s
public static int repeatedStringMatch(String A, String B) { //判断字符串a重复几次可以包含另外一个字符串b,就是不断叠加字符串a直到长度大于等于b,叠加一次计数+1 //看现在的字符串是否包含b,包含就返回,不会包含就再叠加一次,因为可能有半截的在后边,再判断,再没有就返回-1 int count = 0; StringBuilder sb = new StringBuilder(); while (sb.length() < B.l
Java 7中,switch的参数可以是String类型了,这对我们来说是一个很方便的改进.到目前为止switch支持这样几种数据类型:byte short int char String .但是,作为一个程序员我们不仅要知道他有多么好用,还要知道它是如何实现的,witch对整型的支持是怎么实现的呢?对字符型是怎么实现的呢?String类型呢?有一点Java开发经验的人这个时候都会猜测switch对String的支持是使用equals()方法和hashcode()方法.那么到底是不是这两个方法呢
int -> String int i=12345;String s="";第一种方法:s=i+"";第二种方法:s=String.valueOf(i);这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢? String -> int s="12345";int i;第一种方法:i=Integer.parseInt(s);第二种方法:i=Integer.valueOf(s).intValue();这两种方法有什么区别
int本身也要用一串字符表示,前后没有双引号,告诉编译器把它当作一个数解释.缺省情况下,是当成10进制(dec)来解释,如果想用8进制,16进制,怎么办?加上前缀,告诉编译器按照不同进制去解释.8进制(oct)---前缀加0,16进制(hex)---前缀加0x或者0X. string前后加上双引号,告诉编译器把它当成一串字符来解释. 注意:对于字符,需要区分字符和字符表示的数值.比如:char a = 8:char b = '8',a表示第8个字符,b表示字符8,是第56个字符. int转化为s
感谢:http://blog.csdn.net/xiaofei2010/article/details/7434737 以及:http://www.cnblogs.com/nzbbody/p/3504199.html 1. int转string(更多参见:http://www.cnblogs.com/nzbbody/p/3504199.html) #include <iostream> #include <sstream> using namespace std; int main
string int2str(int x) { return x ? num2str(x/10)+string(1,x%10+'0') : "";} int str2int(string s) { int x = 0; for (char it : s) x = x*10+it-'0'; return x;} PS:谁还能更短(>.<)