Java输出问题
public class StringMethod
{
public static void main(String[] args)
{
String s = "This is test string";
System.out.println("原字符串为:" + s);
System.out.println("s.length()为:" + s.length());
System.out.println("s.charAt(8)为:" + s.charAt(8));
System.out.println("s.indexOf('t')为:" + s.indexOf('t'));
System.out.println("s.lastIndex('t')为:" + s.lastIndexOf('t'));
System.out.println("s.substring(8, 12)为:" + s.substring(8, 12) );
System.out.println(""hello,".concat(s)为:" + "hello,".concat(s)); --------有错
char[] chs = new char[20];
s.getChars(8, 12, chs, 0);
System.out.print("chs 为:");
for (int i = 0; i < chs.length; i ++)
{
System.out.print(chs[i]);
}
System.out.println("\n End");
}
}怎样改才能使有错那一行不改变原有意思即输出的hello是带有引号,请高手指点!!!!先谢过
----------------解决方案--------------------------------------------------------
回复 楼主 清风易水
\" 转义----------------解决方案--------------------------------------------------------
跟 \n 和 \t 一样意思.......
----------------解决方案--------------------------------------------------------
System.out.println("\"hello\".concat(s)为:" + "\"hello\"".concat(s)); 改为这样
\为转义字符 \后加“ 表示后面输出引号
----------------解决方案--------------------------------------------------------
System.out.println("\"hello,\".concat(s)为:" + "hello,".concat(s));
----------------解决方案--------------------------------------------------------
明显楼主基础知识没学好
----------------解决方案--------------------------------------------------------