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
Andrews [41]
3 years ago
8

The following code does not work as intended. It is meant to input two test grades and return the average in decimal format:

Computers and Technology
1 answer:
vredina [299]3 years ago
4 0

Answer:

Type casting error

Explanation:

Logically, the program is correct and it is expected to return the average value. However, test1 and test2 are int values and when you applies any algebraic expression on Int, it will result into Int.

So, in this part (test1 + test2 )/2, two integers are adding and the final result is still an integer and this part will act as an integer even if you multiple or divide with any external number.

For example,

test1 = 4

test2 = 5

test1 + test2 = 9

Now, if you divide it by 2, it will still react as an integer portion. So, 9/2 would result in 4 instead of 4.5. All the calculation is done on the right side before assigning it to a double variable. Therefore, the double variable is still getting the int value and your program is not working correctly.

The solution is to typecast the "(test1 + test2 )/2" portion to double using Double.valueOf(test1 + test2)/2 ;

I have also attached the working code below.

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 System.out.println("Hello World");

 Scanner scan = new Scanner (System.in);

 int test1 = scan.nextInt();

       int test2 = scan.nextInt();

       double average = Double.valueOf(test1 + test2)/2 ;

       System.out.println("Answer: " + average);

}

}

You might be interested in
Several users on the second floor of your company's building are reporting that the network is down. you go to the second floor
Svetllana [295]

Answer:

Question users

Explanation:

Q:

Several users on the second floor of your company's building are reporting that the network …

A. Establish a plan of action

B. Question users...

A:

B. Question users

8 0
2 years ago
A text-only forum accessed through a bulletin board service (BBS) is known as a _____.
Tcecarenko [31]

Answer:

newsgroup---for apex

3 0
3 years ago
What types of messages flow across an SDN controller’s northbound and southbound APIs? Who is the recipient of these messages se
Marta_Voda [28]

Answer and Explanation:

Messages flow across an SDN controller's:  

Northbound APIs:  

• Messages which help in read/write state of the network and developing flow tables within the  

state management layer.  

• Notifications for the state-change events.  

• The interaction between the controller and network control applications is done through the  

northbound interface.  

• Network control applications send messages to the controller.  

Southbound APIs:  

• Messages which help for the up-to-date view of the network's state like message for the  

attached link has gone up or down, new devices are joined the network, or indications of the  

device is up or down.  

• Controller's southbound interface is the communication among the controller and the controlled  

devices. Controlled devices are the recipients of the messages sent form the controller.  

3 0
3 years ago
In a bubble sort for a list of length n >= 2, in each iteration, the first step is to compare_______.
Hunter-Best [27]

Answer:

the consecutive two elements and swap them based on the value which is larger if we go for ascending order

Explanation:

bubble sort compares 2 consecutive elements of the list and swap them. in one iteration one value will be placed correctly depending on the sorting order either ascending or descending

7 0
2 years ago
You are adding more features to a linear regression model and hope they will improve your model. If you add an important feature
Ludmilka [50]

Answer:

The answer is "Option A".

Explanation:

Add extra functionality, otherwise, it increases the R-square value, which is defined in the following points:      

  • To incorporate essential elements, R-square is explicitly promoted.
  • It Increases the R-square value, which is an additional feature.
  • It removes the features, which provide the value of the reduce R-square.
  • After incorporating the additional features is used as the model, which is R-square, which is never reduced.
8 0
2 years ago
Other questions:
  • What is the meaning for science?
    14·1 answer
  • Which one of these is NOT a successful budgeting strategy?
    12·2 answers
  • Which option in presentation software can you use to apply a “fly in” effect to the objects on a slide? A)flowchart B)shapes C)
    11·2 answers
  • An additional factor in how an element is rendered is that properties are passed from a parent element to its children in a proc
    15·1 answer
  • The correct order of operations is _____. brackets, exponents, division, multiplication, addition, and subtraction subtraction,
    5·2 answers
  • What data discovery process, whereby objects are categorized into predetermined groups, is used in text mining?
    12·1 answer
  • Mechanisms that combine memory, processing speed, and knowledge to regulate the analysis and flow of information within the info
    5·1 answer
  • Which of the following is the MOST sensitive Personally Identifiable Information (PII) and should be shared cautiously and only
    8·1 answer
  • Like when writing a paragraph, the subject becomes the __________ of the photograph.
    6·1 answer
  • Basil was reading about a new attack that forces the system to abandon a higher cryptographic security mode of operation and ins
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!