1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ivanzaharov [21]
3 years ago
6

What is the problem with the code snippet below? public class Test { public static void main(String[] args) { System.out.println

(cost(10, 4)); } public static void cost(int price, int reps) { for (int i = 0; i < reps; i++) { System.out.print(price); } } }
Computers and Technology
1 answer:
FrozenT [24]3 years ago
6 0

Answer:

The problem in the following snippet is that the function "cost" returns the void and it cannot used as the expression in the print statement

Explanation:

public class Test

{

    public static void main(String[] args)

    {

          System.out.println(cost(10, 4));

     }

     public static void cost(int price, int reps)

     {

           for (int i = 0; i < reps; i++)  

           {

                   System.out.print(price);                

           }  

     }

}

Output:

Main.java:4: error: 'void' type not allowed here

        System.out.println(cost(10, 4));

                               ^

1 error

In the following code the void type is not allowed in the function "cost".

You might be interested in
If Anime Characters were real , Who Would Your Anime Wife Would Be (Tell Who And Why)
ehidna [41]

Answer:

Runa, because  she’s like me I r l lol

Explanation:

3 0
2 years ago
Someone is retiring next year. What would be an appropriate amount of risk to take their investments?
slamgirl [31]
B...............................
7 0
2 years ago
Read 2 more answers
A list of sources used for in-text citations that appears at the end of a document is called:
jolli1 [7]
The correct answer is Works cited page
5 0
2 years ago
Which of the following is an example of data an Earth-observing satellite would collect?
Natalka [10]

Answer:

A

Explanation:

Hopefully this helps

4 0
2 years ago
Based on the condition.
e-lub [12.9K]

Answer:

A subroutine is a block of statements that carries out one or more tasks. ... they share all variables with the rest of the main program. ... Once you have defined a function in your program, you may use it in any appropriate expression, such as: ... Thus, functions can- not change the values of the arguments passed to them.

Explanation:

5 0
3 years ago
Other questions:
  • Ian is working as a sales manager. He has to generate sales reports using mathematical data that his team has collected. Which c
    15·1 answer
  • When you append a(n) ____ to a command, the command is run in a background process?
    8·1 answer
  • In fixed-width files, each record is on a separate line and the fields are separated by a special character.
    7·1 answer
  • IOS jail broken or Android unrooted which is better to hack with
    6·1 answer
  • After adjusting your seat, your _____ should be as close as possible to the backrest
    7·2 answers
  • When you connect a device to your computer for the first time, Windows Media Player selects the ____ method that works best for
    15·2 answers
  • Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If th
    5·1 answer
  • What is keylogging attack?
    13·2 answers
  • I dont uderstand dis my teacher no helping pls help me i need to understand TEch
    10·1 answer
  • Which of the following is an operating system?<br> MacBook Air<br> Windows 10<br> Dell
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!