java string查找
Program 1
程序1
public class iHelp
{
public static void main (String[] args)
{
System.out.println("Google".charAt(3));
}
}
Output
输出量
g
Explanation
说明
String.charAt() is a library function of String class, it returns character from given index of the string. Here, in the statement "Google".charAt(3) will return 'g', because 'g' exists on the 3rd index.
String.charAt()是String类的库函数,它从字符串的给定索引返回字符。 此处,在语句“ Google”中,charAt(3)将返回'g' ,因为'g'存在于第三个索引上。
Program 2
程序2
public class iHelp
{
public static void main (String[] args)
{
System.out.println("Google"+3);
}
}
Output
输出量
Google3
Explanation
说明
In java String, "+" is a concatenation operator, if we concatenate any number or string with the string, it returns that number/string concatenated to the string.
在java字符串中, “ +”是连接运算符,如果我们将任何数字或字符串与字符串连接,它将返回连接到该字符串的数字/字符串。
Here, "Google" is a string and 3 is a number. The resultant string of "Google"+3 will be "Google3".
在这里, “ Google”是一个字符串,而3是一个数字。 结果字符串“ Google” +3将为“ Google3” 。
Program 3
程序3
public class iHelp
{
public static void main (String[] args)
{
System.out.println(10+20);
}
}
Output
输出量
30
Explanation
说明
10+20 is a simple numeric expression, addition will be performed. Therefore, the result will be 30.
10 + 20是一个简单的数字表达式,将执行加法运算。 因此,结果将是30 。
Program 4
程序4
public class iHelp
{
public static void main (String[] args)
{
if(System.out.println(10) == System.out.println(10))
System.out.println("TRUE");
else
System.out.println("FALSE");
}
}
Output
输出量
Compilation error:
编译错误:
Main.java:6: error: 'void' type not allowed here
if(System.out.println(10) == System.out.println(10))
^
1 error
Explanation
说明
The statement System.out.println() does not return anything. Therefore, no value will be for compression. Error will be "void" type not allowed here.
语句System.out.println()不返回任何内容。 因此,没有任何压缩值。 错误将是此处不允许的“ void”类型 。
Program 5
程序5
public class iHelp
{
public static void main (String[] args)
{
System.out.println(10+20+""+40);
}
}
Output
输出量
3040
Explanation
说明
10+20 will be added first, and result of 10+20 will be 30. Then, " " will be concatenated to the 30, so it will become "30" in string. After that, "30"+40 will be "3040" (because if any string/number is added to the string it will concatenate as string).
10 + 20将被首先添加,以及10 + 20的结果将是30。然后,“”将被级联到30,所以它会成为“字符串30”。 此后, “ 30” +40将为“ 3040” (因为如果在字符串中添加了任何字符串/数字,它将串联为字符串)。
Therefore, output will be "3040".
因此,输出将为“ 3040” 。
翻译自: https://www.includehelp.com/java/find-output-programs-java-string-class.aspx
java string查找