Ask Question
29 January, 18:09

What will this method call print to the screen? public void funWithNumbers (double myDouble) { int myInt = (int) myDouble; String myString = ""; while (myInt! = 0) { myString = myInt % 10 + myString; myInt / = 10; } System. out. println (myString); } funWithNumbers (314159)

+4
Answers (1)
  1. 29 January, 22:04
    0
    A string of "314159"

    Explanation:

    Given the code as follows:

    public static void main (String[] args) { funWithNumbers (314159); } public static void funWithNumbers (double myDouble) { int myInt = (int) myDouble; String myString = ""; while (myInt! = 0) { myString = myInt % 10 + myString; myInt / = 10; } System. out. println (myString); }

    This function will convert an input number to an equivalent string. For example, input: 314159 output: "314159"

    Within the function funWithNumbers (), each of the individual digit will be taken from the right. This can be achieved by using modulus operator,%, to get remainder of the input number divided by 10 (Line 11). The remainder is joined with a string, myString.

    To get the subsequent digits from the right, divide the input number by 10 (Line 12) and repeat the same process to extract the digit one by one using modulus operator and concatenate it with myString within the while loop.

    Upon completion of the while loop, a string version of the input number will be generated and printed out to terminal (Line 14).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What will this method call print to the screen? public void funWithNumbers (double myDouble) { int myInt = (int) myDouble; String myString ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers