Ask Question

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. 21 June, 08:11
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers