Question:

Java code... write the output

by  |  earlier

0 LIKES UnLike

Given the following Java code segment:

1. for (int num1 = 5; num1 <= 9; num1 ) {

2. for (int num2 = 1; num2 <= 3; num2 ) {

3. answer = num1 * num2;

4. System.out.print (num1 "*" num2 " = ");

5. System.out.println (answer);

6. }

7. }

How to do this question?

Hmm, the answer = num1 * num2; on line 3,... I don't know which value of num1 and num2 to substitute inside... Can someone also explain the code for me? Thanks

 Tags:

   Report

2 ANSWERS


  1. num1 *num2=5

    num1 *num2=10

    num1 *num2=15

    num1 *num2=6

    num1 *num2=12

    num1 *num2=18

    num1 *num2=7

    num1 *num2=14

    num1 *num2=21

    num1 *num2=8

    num1 *num2=16

    num1 *num2=24

    num1 *num2=9

    num1 *num2=18

    num1 *num2=27

    It&#039;s loops. So basically,  num1 is going to equal 5 until num2 =3, then num1 increments and num1 =6 and num2 starts back at 1 and goes to 3.


  2. When writing to a string or combining strings, you need to use the concatenation sign (&amp;). So to show the output, you need to do:

    System.out.println (num1 &amp; &quot; * &quot; &amp; num2 &amp; &quot; = &quot; &amp; answer)

    If you want, you can email me to ask about any more java code, though I don&#039;t know too much.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.