Q:

Find output programs (Java String class)

belongs to collection: Java find output programs

0

Program 1

public class iHelp
{
	public static void main (String[] args)
	{
		System.out.println("Google".charAt(3));
	}
}

Program 2

public class iHelp
{
	public static void main (String[] args)
	{
		System.out.println("Google"+3);
	}
}

Program 3

public class iHelp
{
	public static void main (String[] args)
	{
		System.out.println(10+20);
	}
}

Program 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");
	}
}

Program 5

public class iHelp
{
	public static void main (String[] args)
	{
		System.out.println(10+20+""+40);
	}
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

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.

Answer Program 2:

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.

Here, "Google" is a string and 3 is a number. The resultant string of "Google"+3 will be "Google3".

 

Answer Program 3:

Output

    30

Explanation

<p10+20 is a simple numeric expression, addition will be performed. Therefore, the result will be 30.</p

Answer Program 4:

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.

Answer Program 5:

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).

Therefore, output will be "3040".

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Find Output of Java program - 1 (Mixed topics)... >>
<< Java find output programs (Autoboxing & Unboxing) ...