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
Alexeev081 [22]
2 years ago
15

(Convert decimals to fractions) Write a program that prompts the user to enter a decimal number and displays the number in a fra

ction. Hint: read the decimal number as a string, extract the integer part and fractional part from the string, and use the BigInteger implementation of the Rational class in Programming
Computers and Technology
1 answer:
Elena L [17]2 years ago
3 0

The given program that prompts the user to enter a decimal number and displays the number in a fraction is:

import java.math.BigInteger;

import java.util.Scanner;

public class Exercise_13_19 {

/** Main method */

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 // Prompt the user to enter a decimal number

 System.out.print("Enter a decimal number: ");

 String[] decimal = input.nextLine().split("[.]");

 // Create a Rational object of the integer part of the decimal number

 Rational r1 = new Rational(new BigInteger(decimal[0]), BigInteger.ONE);

 // Create a Rational object of the fractional part of the decimal number

 Rational r2 = new Rational(new BigInteger(decimal[1]), new BigInteger(

  String.valueOf((int)Math.pow(10, decimal[1].length()))));

 // Display fraction number

 System.out.println("The fraction number is " +

  (decimal[0].charAt(0) == '-' ? (r1).subtract(r2) : (r1).add(r2)));

}

}

Read more about java programming here:

brainly.com/question/26952414

#SPJ1

You might be interested in
Jake is photographing his pet puppy. He wants to preview the image the camera will capture. What part of the camera that is insi
german

A. i think that is right

3 0
3 years ago
Read 2 more answers
What statement should you use to print the value of total with a precision of 5 digits?
Norma-Jean [14]

Answer:

Option A: print("The total is %0.5f" % total)

Explanation:

To ensure the value is rounded to a precision of 5 digits, we have to create a formatted string which is %0.5f. The <em>.5</em> denotes five decimal places and <em>f </em>refers to float data type.

Next, we use the <em>%</em> operator again and followed with the variable <em>total</em>. The % is used as a string modulo operator that will interpolate the value held by the the variable <em>total </em>in the formatted string that we create previously. The interpolated value will be rounded to 5 decimal places. For example, if

total = 256.786789

The output will be 256.78679

5 0
4 years ago
A web directory is a web page that conducts searches of the web to find the words or expressions that you enter? true or false.
Sav [38]
The answer to this is true! hope i helped!
4 0
3 years ago
If you type =5*3 into a cell, what do you expect the answer will be?
Ilya [14]

Answer:

I think 15

what do you mean by cell

Explanation:

3 0
3 years ago
Read 2 more answers
Rajesh wants to collaborate with his friends on a web app to complete on a project. While collaborating online has many advantag
Artist 52 [7]

Answer:

When the provider of the web app he uses goes out of business .

When he has an intermittent internet connection at his home .

Explanation:

It can fully depend on many factors. As well, we can talk to:

Internet reliance

Security

Reduced speed

Browser support

7 0
4 years ago
Other questions:
  • Informs the network interface card to pass packets sent to that address to the ip stack so their contents can be read, and tells
    9·1 answer
  • which of the following is involved in ordering an outline. A.grouping B.merging C.organizing D.arranging
    10·1 answer
  • Remember for a moment a recent trip you have made to the grocery store to pick up a few items. What pieces of data did the Point
    15·1 answer
  • You are given an array of integers, each with an unknown number of digits. You are also told the total number of digits of all t
    7·1 answer
  • The first idea for a communications network was called
    14·2 answers
  • The
    6·2 answers
  • Remember not to use tools that are ________ in any way.
    5·1 answer
  • Please someone do this for me and send a screenshot i really need it for my exams pleaseeee :(<br>​
    10·1 answer
  • Which of the following is the most significant result of technological innovation?
    10·2 answers
  • There are many potential risks associated with the internet. what do we call the distribution and access of illegal copies of di
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!