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
Teenagers and their parents will never understand each other-the generation gap is too big. Its for my grade 11 English speech​
bazaltina [42]

Answer:

lol

Explanation:

lol

7 0
2 years ago
Read 2 more answers
A constructor is just a special type of ______________ that instantiates an object from the class.
Dmitry_Shevchenko [17]

A constructor exists just a special type of subroutine that instantiates an object from the class.

<h3>What  is constructor?</h3>

A constructor exists as a special kind of subroutine in a class. It maintains the same name as the name of the class, and it has no return type, not even void. A constructor exists called with the new operator in order to create a new object.

A constructor exists as a special process of a class or structure in object-oriented programming that initializes a newly constructed object of that type. Whenever an object exists created, the constructor is called automatically. A constructor in Java exists as a special method that is utilized to initialize objects. The constructor exists called when an object of a class is created.

A subroutine exists as a sequence of program instructions that serves a specific task, packaged as a unit. This unit can then be utilized in programs wherever that separate task should be performed.

Hence,  A constructor exists just a special type of subroutine that instantiates an object from the class.

To learn more about constructor refer to:

brainly.com/question/13267121

#SPJ4

8 0
1 year ago
Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 5
omeli [17]

Answer:

The Following are the code to this question:

def cost(miles, milesPerGallon, dollarsPerGallon):##defining a method cost that accepts three parameter

   return miles / milesPerGallon * dollarsPerGallon# calculate cost and return it value  

milesPerGallon = float(input('Enter miles/Gallon value: '))#defining variable milesPerGallon for user input  

dollarsPerGallon = float(input('Enter dollars/ Gallon value: '))#defining variable dollarsPerGallon for user input

print('{:.5f}'.format(cost(10, milesPerGallon, dollarsPerGallon)))#call method and print its value

print('{:.5f}'.format(cost(50, milesPerGallon, dollarsPerGallon)))#call method and print its value

print('{:.3f}'.format(cost(400, milesPerGallon, dollarsPerGallon)))#call method and print its value

Output:

Enter miles/Gallon value: 20.0

Enter dollars/ Gallon value: 3.1599

1.57995

7.89975

63.198

Explanation:

In the above-given code, a method "cost" is defined, that accepts three value "miles, milesPerGallon, and dollarsPerGallon" in its parameter, and use the return keyword for calculating and return its value.

In the next step, two variable "milesPerGallon, and dollarsPerGallon" is declared, that use the input method with float keyword for input floating-point value.

After input value, it uses a print method with different miles values, which are "10,50, and 400", and input value to pass in cost method to call and print its return value.

5 0
3 years ago
Heuristics are not always completely accurate.<br><br><br> Correct or wrong?
Alisiya [41]

Answer:

They are not always right or the most accurate.

Explanation:

Judgments and decisions based on heuristics are simply good enough to satisfy a pressing need in situations of uncertainty, where information is incomplete.

8 0
2 years ago
Read 2 more answers
The structure and organization of data in a database is called a data ____.
Aleks [24]
Answer:  "hierarchy" .
_____________________________________________________
6 0
2 years ago
Other questions:
  • When you declare an array, _____________________ You always reserve memory for it in the same statement You might reserve memory
    9·1 answer
  • 1. An Excel file is called a workbook?<br> A) True<br> B) False
    6·2 answers
  • What could be one rule to help your friend to blog safely
    6·2 answers
  • You are required to design a 4-bit even up-counter using D flip flop by converting combinational circuit to sequential circuit.
    15·1 answer
  • Write a program that reads two fractions such as 1/2 and 1/4 and computes and stores the sum, the difference, the product and th
    15·1 answer
  • Can you please answer the question in the picture ! :)
    6·1 answer
  • Use the syntax SELECT ________ (expression) [Column Name] to limit the result set to the number of rows defined by the expressio
    10·1 answer
  • Open excel program then use the (IF) function to fill the column of (Expensive/Cheap) then save your
    9·1 answer
  • The original programs awaiting tanslation is called​
    11·1 answer
  • A manager suspects that one of his team members has been fraudulently accessing confidential and sensitive information and breac
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!