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
mars1129 [50]
3 years ago
10

Write a program to convert a fraction to a decimal. Have your program ask for the numerator first, then the denominator. Make su

re to check if the denominator is zero. If it is, print out "Error - cannot divide by zero."
Computers and Technology
1 answer:
Anton [14]3 years ago
3 0
<h2>Answer:</h2>

import java.util.Scanner;

public class FractionToDecimal {

   public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       

       System.out.println("Please enter the numerator");

       double numerator = input.nextDouble();

       System.out.println("Please enter the denominator");

       double denominator = input.nextDouble();

       

       if(denominator == 0){

           System.err.println("ERROR - Cannot divide by zero.");

       }

       else {

           System.out.println("The result is " + (numerator/denominator));

       }

       

   }

   

}

<h2>Explanation:</h2>

// import the Scanner class to allow for user input

import java.util.Scanner;

// 1. Declare a class

public class FractionToDecimal {

   // 2. Write the main method

   public static void main(String[] args) {

       

       // 3. Create an object of the Scanner class called <em>input</em>

       Scanner input = new Scanner(System.in);

       

       // 4. Prompt the user to supply the numerator

       System.out.println("Please enter the numerator");

       

       // 5. Declare and initialize a variable <em>numerator </em>to hold the numerator

       // supplied by the user.

       // The numerator is of type double since the program does not

       // specify any. With a double both integer and floating point numbers

       // will be supported.

       double numerator = input.nextDouble();

       

       // 6. Prompt the user to enter the denominator

       System.out.println("Please enter the denominator");

       // 7. Declare and initialize a variable <em>denominator </em>to hold the

       // denominator supplied by the user.

       // The denominator is also of type double since the program does not

       // specify any. With a double, both integer and floating point numbers

       // will be supported.

       double denominator = input.nextDouble();

       // 8. Check if the denominator is or is not zero.

       // if it is zero, display an error message        

       if(denominator == 0){

           System.err.println("ERROR - Cannot divide by zero.");

       }

       // if it is not zero, then print out the result of the division

       else {

           System.out.println("The result is " + (numerator/denominator));

       }

       

   }                       // end of main method

   

}                            // end of class declaration

Please Note:

The code above has been written in Java.

The explanation segment contains comments to explain every line of the code.

But a few things are still worth noting;

i. Dividing the numerator by the denominator will convert a fraction to decimal.

ii. The object of the Scanner class <em>input </em> is used to get the inputs (numerator and denominator) from the user. Since the inputs are going to be integers or doubles, the nextDouble() method of the the Scanner class is used.

iii. If the denominator is zero, an error message will be displayed. I have used the System.err.println() method for that rather than the regular System.out.println() method. The difference is that the former will print out the error text in red color.

iv. Notice also that the else statement in the code will perform the division and also print out the result of the division along side with some text.

<em>Hope this helps!</em>

You might be interested in
Suppose cell C5 contains the formula =B$6+C1.
ddd [48]

Answer:

=A$6+B4 will be in B8

=B$6+C6 will be in C10

=C$6+D2 will be in D6

=D$6+E1 will be in E5

Explanation:

$ sign is used to lock a certain column or row value, with the $ sign we can create an absolute reference which will remain unchanged as we copy our formula from one cell to another.

As formulars are copied, the references change respectively.

With =B$6+C1 in C5 ; As we move up or down of cell C5, only the row numbers will change that is formula in C6 becomes =B$6+C2.

As we move left and right, the column alphabet will also experience change like the rows did.

Only the absolute reference won't change no matter the direction.

Hence,

=A$6+B4 ; A and B means one move to the left of C5 and 4 signifies, 3 moves downward of C5 that gives B8

=B$6+C6 ; B and C means no horizontal change, 6 means 5 moves downward of C5 which gives C10

=C$6+D2 ; C and D means 1 move to the right and 2 means one move downward of C5 which gives D6

=D$6+E1 ; D and E means 2 moves to the right and 1 means no vertical change from C5 ; which gives E5

4 0
2 years ago
Which of the following is NOT a long-term storage device?
neonofarm [45]

The storage device which is not a long-term storage device is: D. RAM.

<h3>Types of computer memory.</h3>

In Computer technology, there are two (2) main types of memory or storage location for software program (application) that are being used on a computer and these include the following;

  1. Read only memory (ROM)
  2. Random access memory (RAM)

<h3>What is RAM?</h3>

RAM is an abbreviation for random access memory and it can be defined as a volatile and temporary storage (memory) location that is used for currently opened software program (application) and computer data.

In conclusion, we can reasonably and logically deduce that the storage device which is not a long-term storage device is random access memory (RAM).

Read more on RAM here: brainly.com/question/13748829

#SPJ1

3 0
1 year ago
The first row in a table is referred to as the _____ row and the last row is considered the _____ row.
Juliette [100K]

the first row in a table is classed as the header row.

and with the last one I'm not sure because as far as I know there's not considered a last row.

6 0
3 years ago
In the Happy Valley School System, children are classified by age as follows:less than 2, ineligible2, toddler3-5, early childho
Greeley [361]

Answer:

int age = 10;

switch (age){

case 0:

case 1:

System.out.println("ineligible");

break;

case 2:

System.out.println("toddler");

break;

case 3:

case 4:

case 5:

System.out.println("early childhood");

break;

case 6:

case 7:

System.out.println("young reader");

break;

case 8:

case 9:

case 10:

System.out.println("elementary");

break;

case 11:

case 12:

System.out.println("middle");

break;

case 13:

System.out.println("impossible");

break;

case 14:

case 15:

case 16:

System.out.println("high school");

break;

case 17:

case 18:

System.out.println("scholar");

break;

default:

System.out.println("ineligible");

}

Explanation:

In java and many other programming languages, a switch statement is a way of having multiple branching options in a program. This is usually considered a more efficient way than using multiple if....else if statements. and the expression variables could be byte, char int primitive data types. etc. every branch (option) in a switch statement is followed by the break statement to prevent the code from "falling through". In the question The variable age is declared as an int and initialized to 10. and tested against the conditions given in the question.

7 0
3 years ago
What OC level is primarily used as a regional isp backbone, and occasionally by very large hospitals, universities, or other maj
Neporo4naja [7]

The OC level is primarily used as a regional ISP backbone, and occasionally by very large hospitals, universities, or other major enterprises is <u>OC-48.</u>

<u></u>

<h3>What is the greatest amount of throughput provided by an OC 12?</h3>

OC-12 is a network line with communication speeds of up to 622.08 Mbit/s (payload: 601.344 Mbit/s; overhead: 20.736 Mbit/s). OC-12 lines are generally used by ISPs as wide area network (WAN) connections.

<h3>When using frame relay What is the appellation of the identifier?</h3>

A data-link connection identifier (DLCI) determines the Frame Relay PVC. Frames are routed through one or more virtual circuits determined by DLCIs.

Each DLCI has a permanently configured switching path to a particular destination

To learn more about OC level , refer

brainly.com/question/25899244

#SPJ4

<u></u>

5 0
1 year ago
Other questions:
  • Pros and cons of Processor Throttling or Scaling?
    13·1 answer
  • An important advantage of using GUI data-entry objects is that you often can control what users enter by limiting their options?
    6·1 answer
  • Will a tablecloth that is 155 cm long cover a table that is 1.6 m long?
    12·2 answers
  • (Financial application: compound value) Suppose you save $100 each month into a savings account with the annual interest rate 5%
    8·1 answer
  • What are some (free) good animation websites (for PC/Microsoft) for a short informational video about homelessness?
    15·1 answer
  • why is there a need of properly interpreting teacher's/manufacturer's specifications before operating any food processing equipm
    9·1 answer
  • How many Iron molecules are in the compound Fe4O2?
    15·2 answers
  • The benefit of host and guest operating system difference is:
    8·2 answers
  • Which of the following is the best example of an installation issue?
    6·2 answers
  • Select the correct word to complete the sentence
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!