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
Using an array, double each of the following values and print each result: values = [1.1, 10, 4.55, 30004, 0.2]
11111nata11111 [884]
Values = [1.1, 10, 4.55, 30004, 0.2]
3 0
3 years ago
I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
S_A_V [24]

Answer:

Working with text in presentation programs is similar to working with text in other application, audience size influences font size, and font size and font color can be changed in presentations.

6 0
3 years ago
Read 2 more answers
Robert and Anne, a married couple filing jointly, have an adjusted gross income of $68,676. They claim two exemptions, and can d
artcher [175]

Answer:

the answer is B

Explanation:

Just took the test

8 0
2 years ago
Read 2 more answers
Which organization provides a free, online html5 validator application to ensure that a webpage's html tags follow the rules for
SashulF [63]

The organization provides a free, online html5 validator application to ensure that a webpage's html tags follow the rules for html5 is the W3C.

<h3>What does the W3C do?</h3>

The W3C's is known to help to create protocols and rules that makes sure that long-term  development of the Web.

Therefore, we can say that The organization provides a free, online html5 validator application to ensure that a webpage's html tags follow the rules for html5 is the W3C.

Learn more about The W3C  from

brainly.com/question/11179793

#SPJ1

3 0
2 years ago
Which of the following is not a computer protocol? FTP, SMTP, ISP, or TCP
aliina [53]
ISP stands for internet service provider so that's the one
8 0
3 years ago
Read 2 more answers
Other questions:
  • Don is the superintendent of the county school system. What task might Don
    8·1 answer
  • What tips or techniques should you keep in mind when shooting photographs on a rainy day?
    6·1 answer
  • What are the uses of joystick​
    13·1 answer
  • A user can easily moved to the end of document by pressing what key combination?
    8·2 answers
  • Which technology enables afloat forces to communicate more securely and to operate in a more dispersed manner?
    6·1 answer
  • If you want to store the information that a user types in response to the input() function, what do you need to do? (select the
    11·1 answer
  • RAID level ________ refers to disk arrays with striping at the level of blocks, but without any redundancy. A. 0 B. 1 C. 2 D. 3
    7·1 answer
  • What is the second row of letters in the keyboard called?
    6·1 answer
  • 10.
    12·1 answer
  • What is the simplest form of backing up data?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!