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
How many mb are in a gb?
frosja888 [35]

Answer:

1000 megabytes are in a gigabyte

Explanation:

3 0
2 years ago
If you had an idea for a new software company, what would be the best approach to help make it a successful business? develop a
Klio2033 [76]

Answer:

develop a business plan to describe how to maintain and grow revenues

Explanation:

4 0
3 years ago
Read 2 more answers
What is software piracy
Tju [1.3M]
Software piracy is the illegal copying, distribution, or use of software.
8 0
3 years ago
Read 2 more answers
What type of software repairs or improves a larger application that is already installed on a system?
earnstyle [38]

Answer:

<h2>Mapping</h2>

Explanation:

<h2>Hope it helps you</h2>
7 0
2 years ago
Read 2 more answers
You are the administrator for the contoso.com website. recently, the server hosting the website had a failure that caused it to
Alisiya [41]
Protecting the Power supply
Adding disk Arrays
Install an NLB Cluster
4 0
3 years ago
Other questions:
  • Ascending and descending are examples of
    5·2 answers
  • What do you have to do to see the html code on a website?
    15·2 answers
  • Who were called “freedmen” during the reconstruction period?
    15·2 answers
  • Which is not a factor that leads to technological advancement?
    8·1 answer
  • A sales transaction was coded with an invalid customer account code (XXX-XX-XXX rather than XXX-XXX-XXX). The error was not dete
    12·1 answer
  • Which type of protocol allows for a secure data transmission using encryption methods?
    7·1 answer
  • What is computer topology​
    5·2 answers
  • Computer Graphics:
    13·1 answer
  • How to make text icome one word at a timen filmora
    10·1 answer
  • Discovery of a vulnerability in a software program can potentially be sold to the government. Group of answer choices True False
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!