Question:

What is the type of parameter to be given for the method \texttt{parseInt()?}

Show Hint

Remember: \texttt{Integer.parseInt()} converts a \textbf{String} into an \textbf{int}. Input is text, output is integer.
  • double
  • String
  • char
  • int
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understand the use of \texttt{parseInt()}.
In Java, \texttt{parseInt()} is a method used to convert a number written in text form into an integer value. This method is commonly written as: \[ \texttt{Integer.parseInt("123")} \] Here, the method reads the characters inside quotation marks and converts them into the integer 123.
Step 2: Identify the required parameter type.
Since \texttt{parseInt()} converts text into an integer, the input must be a String. That means the method expects something like: \[ \texttt{"45"}, \texttt{"100"}, \texttt{"786"} \] So, the type of parameter given to \texttt{parseInt()} is String.
Step 3: Compare with the given options.
  • (A) double: Incorrect. A double is already a numeric data type and is not the parameter type for \texttt{parseInt()}.
  • (B) String: Correct. \texttt{parseInt()} accepts a String and converts it into an integer.
  • (C) char: Incorrect. A single character is not the standard parameter type for this method.
  • (D) int: Incorrect. The purpose of \texttt{parseInt()} is to produce an int, not to accept one as input.
Step 4: Conclusion.
Therefore, the type of parameter to be given for the method \texttt{parseInt()} is String.
Final Answer:String.
Was this answer helpful?
0
0

Questions Asked in ICSE Class X board exam

View More Questions