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
A network with 6 bits remaining for the host portion will have how many usable hosts?​
Readme [11.4K]
<span>A network with 6 bits remaining for the host portion will have 62 usable hosts. The netmask is </span><span>255.255.255.192/26, the shorthand is [6-bit] which is equal to the number of addresses as <span>= 62 hosts + 1 bcast + 1 net base</span></span>
6 0
3 years ago
What is virtual memory?
slega [8]
Not a real memory but it points to physical memory.
3 0
3 years ago
10. Two technicians are discussing recycling specifications for refrigerant. Technician A says that refrigerant oil with 5,000 p
NARA [144]

Answer:

a

Explanation:

8 0
3 years ago
Which of the following did you include in your notes?
iVinArrow [24]

Answer:

How you will be innovative in what you offer

Explanation:

personally I think all 3 but it is what it is

6 0
3 years ago
Which of the following statements is false?
GrogVix [38]

Answer:

bnnnnn A1

Explanation:

bnnnnnjm

8 0
2 years ago
Other questions:
  • Given a scanner reference variable named input that has been associated with an input source consisting of a sequence of integer
    14·2 answers
  • How do solar cells translate heat energy into mechanical energy
    13·1 answer
  • Ada lovelace designed the first computer
    7·1 answer
  • Electricity is moved from place to place a long __________​
    14·2 answers
  • Five examples of technology in community​
    7·2 answers
  • What is your biggest takeaway on that subject?​
    8·1 answer
  • Jackie is planning a surprise birthday party for her best friend and is researching a location to have the party. Jackie found a
    6·1 answer
  • Brainly Question
    14·2 answers
  • We can find out how robots work by looking in detail at the smaller parts. What do we call this?
    6·1 answer
  • Basics of visual basic
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!