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
What is the significance of the vertical columns of the periodic table? what is the significance of the horizontal rows?
olga2289 [7]

Yes, horizontal rows are periods. “All of the elements in a period have a similar number of atomic orbitals. Each element in the top row (the principal time frame) has one orbital for its electrons. The greater part of the components in the second column (the second time frame) has two orbitals for their electrons. It goes down the occasional table that way. As of now, the most extreme number of electron orbitals or electron shells for any element is seven."<span>

<span>The vertical columns are groups. "The elements in a group have the same number of electrons in their outer orbital [and thus the same charge]. Every element in the first column (bunch one) has one electron in its external shell. Each element on the second segment (assemble two) has two electrons in the external shell. As you continue tallying the segments, you'll know what numbers of electrons are in the external shell.</span></span>

7 0
4 years ago
c++ design a class named myinteger which models integers. interesting properties of the value can be determined. include these m
klemol [59]

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. class myinteger {
  4.    
  5.    private:
  6.        int value;
  7.        
  8.    public:
  9.        myinteger(int x){
  10.            value = x;
  11.        }
  12.        
  13.       int getValue(){
  14.           return value;
  15.       }
  16.        
  17. };
  18. int main()
  19. {
  20.    myinteger obj(4);
  21.    cout<< obj.getValue();
  22.    return 0;
  23. }

Explanation:

Firstly, we use class keyword to create a class named myinteger (Line 5). Define a private scope data field named value in integer type (Line 7 - 8).

Next, we proceed to define a constructor (Line 11 - 13) and a getter method for value (Line 15 -17) in public scope. The constructor will accept one input x and set it to data field, x. The getter method will return the data field x whenever it is called.

We test our class by creating an object from the class (Line 23) by passing a number of 4 as argument. And when we use the object to call the getValue method, 4 will be printed as output.

4 0
4 years ago
A(n) ________ CPU has two processing paths, allowing it to process more than one instruction at a time.
lions [1.4K]
C. Dual-core is the answer
3 0
4 years ago
Read 2 more answers
Write MVCTester.java. When the program starts, the initial screen displays a button labeled "add", a blank text area, and a text
Debora [2.8K]

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

Explanation:

import java.awt.event.*;  

import java.awt.geom.Area;

import javax.swing.*;

class MVCTester implements ActionListener{

JButton b; //button

JTextField t1; //textfiled

JTextArea area; //text area

MVCTester(){

JFrame f=new JFrame("Button Example");

//button

b=new JButton("add");  

b.setBounds(0,0,125,27);  

f.add(b);  

b.addActionListener(this);  

//textfiled

t1=new JTextField();  

t1.setBounds(0,161,125,24);  

f.add(t1);

//textarea

area=new JTextArea();  

area.setBounds(0,28,123,130);  

f.add(area);

area.setColumns (17);

area.setLineWrap (true);

area.setWrapStyleWord (false);

f.setSize(125,225);

f.setLayout(null);  

f.setVisible(true);

}

"at"Override

public void actionPerformed(ActionEvent arg0) {

Control c=new Control(area,t1,b);

}  

}  

class Control {

Control(JTextArea area,JTextField t1,JButton b){

//simple logic getting text of text area adding text of textfiled and setting the text to text area

area.setText(area.getText()+t1.getText()+"\n");

t1.setText("");

}

}

public class Modal{

public static void main(String[] args) {  

MVCTester be=new MVCTester();

}

}

8 0
3 years ago
Read 2 more answers
Why is contrast important when designing a web page
Phantasy [73]

Contrast is important when designing a web page for many reasons. One of the most important reasons is because if you don't have contrast, you won't be able to read what is written on the page. Your eyes will have to strain really hard or it just simply won't be possible to read at all. Another really important reason is that contrast makes the web page look visually appealing. Whereas, if you don't have contrast it is all kind of jumbled together. As you can see there is a plethora of reasons contrast is important.

I hope that helps u!!

:)

8 0
3 years ago
Other questions:
  • Pedestrians, cyclists, horse drawn vehicles and wheel chair users are known as ___________
    6·2 answers
  • Which Windows feature captures and stores copies of folders and files at specific points in time, allowing users or administrato
    10·1 answer
  • Write a program to read in a two values row and col to initialize a 2D array using those values. Then create a function FindTran
    15·1 answer
  • Your friend sees an error message during Windows startup about a corrupted bootmgr file. He has another computer with a matching
    12·1 answer
  • "Two technicians are discussing FWD driveshaft service. Technician A says that removal of the driveshaft usually requires partia
    15·1 answer
  • Jason is driving 1,050 miles from Miami, Florida, to New
    15·1 answer
  • What is the term meaning a Java object that has attributes and methods?
    12·1 answer
  • Which of the following statements is true?
    5·2 answers
  • Write a recursive decent algorithm for a java while statement, a Javas if statement , an logical/mathematical expression based o
    5·1 answer
  • Silicone rubber and urethane caulks generally give the ____________ overall performance for exterior building envelope applicati
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!