黑马程序员技术交流社区
标题:
count+""和"count"有什么区别?
[打印本页]
作者:
奋发吧小白
时间:
2014-9-17 21:51
标题:
count+""和"count"有什么区别?
本帖最后由 奋发吧小白 于 2014-9-17 21:54 编辑
package copydirectory;
import java.util.*;
import java.io.*;
public class RunTime {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Properties porp = new Properties();
File file = new File("D:\\info.txt");
if(!file.exists())
{
file.createNewFile();
}
FileInputStream fis = new FileInputStream(file);
porp.load(fis);
int count = 0;
String value = porp.getProperty("time");
if(value!=null)
{
count = Integer.parseInt(value);
if(count>6)
{
System.out.println("您使用次数已到,请激活");
return;
}
}
count++;
porp.setProperty("time", count+"");
//setProperty() 方法两个参数 都是 String 类型,count+""和“count”这两种写法 不都是String类型吗?
//为什么“count”这样写 程序就不能正常运行?
FileOutputStream fos = new FileOutputStream(file);
porp.store(fos, "");
fis.close();
fos.close();
}
}
作者:
苏乞儿
时间:
2014-9-17 22:02
定义的count是个整型的变量,如果是“count”那就是字符串count了,跟count变量的值没有任何关系了,count+“”:是把count变量的值变成字符串的。
作者:
奋发吧小白
时间:
2014-9-17 22:04
苏乞儿 发表于 2014-9-17 22:02
定义的count是个整型的变量,如果是“count”那就是字符串count了,跟count变量的值没有任何关系了,count+ ...
谢谢 受教了!
作者:
pvting
时间:
2014-9-18 00:48
同样受教了,thanks
作者:
MeryStyle
时间:
2014-9-18 08:51
一楼正解!!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2