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
What are the binary symbols?
alexgriva [62]

Answer:

Explanation:

a binary number is a number expressed in the base-2 numeral system or binary numeral system

4 0
3 years ago
Read 2 more answers
What are the benefits of building blocks?
BartSMP [9]

I'm not sure if this is what you're looking for but you can benefit from using the Building Blocks feature in Word. Building blocks are pieces of document content or pre-defined items, like tables, lists, headers, and text boxes. They can be used again and again in Word files on your computer.

Hope this helps

8 0
3 years ago
Read 2 more answers
Select the correct answer from each drop-down menu. Computer memory stores data as a series of 0s and 1s. In computer memory, re
attashe74 [19]

Answer:

Zero (0); one (1).

Explanation:

Boolean logic refers to a theory of mathematics developed by the prominent British mathematician, called George Boole. In Boolean logic, all variables are either true or false and are denoted by the number "1" or "0" respectively; True = 1 or False = 0.

The memory of a computer generally stores data as a series of 0s and 1s. In computer memory, zero (0) represents the absence of an electric signal i.e OFF and one (1) represents the presence of an electric signal i.e ON.

4 0
3 years ago
Mesh networks:__________.
postnew [5]

Answer:

b. typically contain more circuits in the network than in star or ring networks

Explanation:

In mesh architecture, all computers are connected to each other. In mesh all nodes connect directly and non hierarchical to each other so as  to efficiently route data.

Mesh combines the benefits of both ring and star networks. It  usually provide relatively short routes through the network (compared to ring networks) and provide  many possible routes through the network to prevent one circuit from becoming overloaded (as compared to star network).  Mesh network uses decentralized routing with each network performing its own routing.

Mesh network typically contain more circuits in the network than in star or ring networks and are more expensive than ring networks

7 0
3 years ago
To place the caption at the top of the image you will need to change the ________
makkiz [27]

wrong!! it was postion!!

4 0
3 years ago
Other questions:
  • Why is the keyboard arranged in the QWERTY style?
    6·2 answers
  • This type of technology does not come with a keyboard or mouse for input
    11·2 answers
  • Design a hierarchy c hart or flowchart for a program that calculates the current balance in a savin gs account. The program must
    8·1 answer
  • A computer record is used to store all the information about one transaction, but several such records must be used to store the
    12·1 answer
  • Which of the following are incident priorities?
    9·1 answer
  • 9. Lael wants to determine several totals and averages for active students. In cell Q8, enter a formula using the COUNTIF functi
    9·1 answer
  • What is the output for the following code?<br><br> print (5*4+5)
    11·1 answer
  • Full form of http.<br>wrong answer will be reported ​
    6·2 answers
  • Queries are questions true or false?
    9·1 answer
  • A natural language processor comes across a sentence that contains the word “weightless.” The morphology component identifies th
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!