Computer Applications
Predict the output of the following Java program snippet:
String n1 = "46", n2 = "64";
int total = Integer.parseInt(n1) + Integer.parseInt(n2);
System.out.println("The sum of " + "46 " + "and" + " 64" + " is " + total);
Java
Java String Handling
52 Likes
Answer
The sum of 46 and 64 is 110
Working
Integer.parseInt() method will convert the strings n1 and n2 to their corresponding numerical integers. So, 46 and 64 are added as numerical values and the result 110 is stored in int variable total.
Answered By
28 Likes
Related Questions
Write down the syntax to check if the second character of a String(str) is in upper case.
Predict the output of the following Java program snippet:
String str = "Computer Applications" + 1 + 0; System.out.println("Understanding" + str);
Predict the output of the following Java program snippet:
boolean p; p = ("BLUEJ".length() > "bluej".length()) ? true: false;
Predict the output of the following Java program snippet:
String str = "Information Technology"; int p; p = str.indexOf('n'); System.out.println(p);