Ask Question
23 February, 08:08

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)

+1
Answers (1)
  1. 23 February, 10:12
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers