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
You cannot advance slides during the slide show by pressing the PAGE DOWN key
noname [10]
<span>You cannot advance slides during the slide show by pressing the PAGE DOWN key.
This is a true statement.
</span>
4 0
3 years ago
Analyze the code and identity the value of variable a,b and c after the code execution. int a=40, b=50, c=60; if(! (a&gt;=40)) b
AlekseyPX

Answer:

a=40,b=30,c=60

The answer is B

7 0
3 years ago
Turns on her laptop and gets the error message "OS NOT FOUND." She checks the hard disk for damage or loose cable, but that is n
Serjik [45]
It needs an Operating System like a cable or something that will help it operate look for more and double check
3 0
3 years ago
In a relational database design, all relationships are expressed by ________.
velikii [3]
Explain what is meant by a limited data set and how this HIPAA rule may affect medical assistants
8 0
3 years ago
Why is it important for element IDs to have meaningful names?
wlad13 [49]

Answer:

so a program can reference it; however, it does not necessarily need an event handler

Explanation:

8 0
3 years ago
Other questions:
  • Jill needs to create a chart for technology club that shows what percentage of total students in the school play video games. Wh
    11·2 answers
  • The following program includes fictional sets of the top 10 male and female baby names for the current year. Write a program tha
    15·1 answer
  • Describe mobile computing
    7·1 answer
  • Which is a benefit of peer-to-peer networking?
    10·1 answer
  • You can toggle between different types of references by pressing the ____ key on your keyboard.
    15·1 answer
  • Please find one organization that has recently adopted virtualization and summarize their reasons for taking this approach. What
    12·1 answer
  • Which of the following should you consider when choosing a file format?
    9·2 answers
  • What are the paparazzi?
    8·1 answer
  • After a group sets a project schedule, members should be prepared to
    7·1 answer
  • Which web-authoring software enables users to create sophisticated web pages without knowing any html code?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!