58.0k views
0 votes
Write a statement that assigns numCoins with numNickels + numDimes. Ex: 5 nickels and 6 dimes results in 11 coins. Note: These activities may test code with different test values. This activity will perform two tests: the first with nickels = 5 and dimes = 6, the second with nickels = 9 and dimes = 0.

1 import java.util.Scanner;
2
3 public class AssigningSum {
4 public static void main(String[] args) {
5 int numCoins;
6 int numNickels;
7 int numDimes;
8
9 numNickels = 5;
10 numDimes - 6;
11
12 /* Your solution goes here
13
14 System.out.print("There are ");
15 System.out.print(numCoins);
16 System.out.println(" coins");
17 }
18 }

User Jichao
by
4.8k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

The statement solution was added to the code and then the code was repeated in order to create the second test case with 9 nickels and 0 dimes. The outputs for both test cases can be seen in the attached image below.

import java.util.Scanner;

class AssigningSum {

public static void main(String[] args) {

int numCoins;

int numNickels;

int numDimes;

numNickels = 5;

numDimes = 6;

/* Your solution goes here */

numCoins = numNickels + numDimes;

System.out.print("There are ");

System.out.print(numCoins);

System.out.println(" coins");

// TEST CASE 2

numNickels = 9;

numDimes = 0;

/* Your solution goes here */

numCoins = numNickels + numDimes;

System.out.print("There are ");

System.out.print(numCoins);

System.out.println(" coins");

}

}

Write a statement that assigns numCoins with numNickels + numDimes. Ex: 5 nickels-example-1
User Lakshman Pilaka
by
5.4k points