2.4 Code Practice: Question 2

Write a program that accepts a number as input, and prints just the decimal portion. Your program should also work if a negative number is inputted by the user.

Enter a number: 15.789
Sample Output
0.789

Can someone please help me with this because I’m so stuck

Answers

Answer 1

The code is in Java.

It calculates the decimal portion of a number by subtracting the integer portion from the number. It also uses if structure to check if the number is a negative one.

Comments are used to explain each line of code.

//Main.java

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 //Initialize the Scanner object to be able to get input

 Scanner input = new Scanner(System.in);

 

 //Declare the variables

 double number, decimalPortion;

 

 //Ask the user to enter a number

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

 number = input.nextDouble();

 

 //Get the decimal portion of the number by subtracting the integer part from the number

 decimalPortion = number - (int) number;

 

 //If the number is negative one, multiply the decimal portion with -1 to convert it to a positive value

 if(number < 0)

     decimalPortion *= -1;

 

 //Print the decimal portion

 System.out.println(decimalPortion);

 

}

}

You may see a similar question in the following link:

brainly.com/question/17132559


Related Questions

My study background is business. I am doing a bachelor of business administration. My major course is management information of the system. But I want to do data science. I know the journey is typically hard for me. In future , it will be demandable if I do data science in master's . Have I made a good decision?

Answers

Answer:

Yes,I think your going on right path! Keep up the hard work ! You got this!

Computers can give you a false sense of security. O True False​

Answers

Answer:

True in my opinion is this for a test?

Explanation:

WILL GIVE BRAINLIEST!!!!!!!!
Trade-offs are the moral principles and values that guide conduct within a group of people.


Group of answer choices


True


False

Answers

yes trueso true true true

Convert the following into binary system
and vice versa.
106​

Answers

It would be 1101010 in binary
It would be 1101010, I think

Which term refers to actions that you would typically perform on a computer to revive it if it functions in an unexpected manner?
The corrective action(s) that you need to perform on a computer in case it functions in an unexpected manner is called

Answers

Answer:

Reboot?

Explanation:

Hard to tell from the information provided.

pls answer fast in five mins​

Answers

The answer is true!! I hope this helps!!

Which of the following is not an operating system
A.LINUX
B.MAC OS
C.NEXUS
D.WINDOWS

Answers

Answer:

C

Explanation:

I hope this helped.

Answer:

I honestly don’t know... But I’m still gettin that credit Broski

Explanation:

New technology is driven by new discoveries in the _________ field.
Group of answer choices

finance

geology

mathematics

science

Answers

Answer:

science.......... ..

15. The legal right to control the
production and selling of a book, play,
film and software is known as
A. Production right
B. Copyright
C. Trade mark
D. Patent​

Answers

the correct answer copyright

Answer:

I believe the answer is copyright

Explanation:

Samantha was working on a Word document and the horizontal and vertical margins disappeared. Which solution will fix the problem? Close the Word document and reopen it. Click on the View Ruler button located at the top of the vertical scroll bar on the right-hand side of the screen. Double-click in the ruler area to redisplay the ruler. Click on the View Ruler button located at the top left-hand side of the screen that looks like an L.​

Answers

Answer:

B

Explanation:

Click on the View Ruler button located at the top of the vertical scroll bar on the right-hand side of the screen is the solution will fix the problem. Hence, option B is correct.

What is MS Word DOC?

Microsoft Word is a word processor that may be used to create papers, letters, reports, and other types of writing of a professional caliber. It includes sophisticated capabilities that give you the best formatting and editing options for your files and projects.

Microsoft Word documents can be opened and edited in Docs. Even better, you may download your document as a Word document with a typical Word extension. But Docs also allows you to export other file types.

It is simple to modify huge sections of text, alter the flow between pages, change font sizes and styles, and perform other operations with Word and the DOC format.

Thus, option B is correct.

For more information about MS Word DOC, click here:

https://brainly.com/question/9174181

#SPJ2

Which of the following is a correct variable name?
Low temperature
7temperature
low--temperature
o low_Temperature

Answers

Answer:

low_temperature

Explanation:

Required

Select which of the given options is correct

In programming;

Variable names don't contain space; as in Low temperature

Variable names don't begin with numbers; as in 7temperature

Variable names don't contain dashes; as in low--temperature

However, variable names may contain underscore; as in low_Temperature;

Hence;

Option D answers the question

(minimum 4 sentences) What is cyber security and why is it important

Answers

Answer:

A cyber security that is used for people being rude and disrespectful online.A cyber security is also used so that none of your personal information gets out.It is important to have  cyber security because it keeps all your personal data safe.Cyber security is good to have if you have a job that has information about other people saved.

Explanation:

it is used to replace numeric number of a website​

Answers

greatflombles or gr8flombles or go2flombles

What is the difference between operating systems and application software?
* Application software translates itself into language for the BIOS, whereas operating systems are what users
interact with
Application software is what the user interacts with, and operating systems are what translate application
software.
Application software is located within the hardware, and operating systems are what the user interacts with.
Application software is located within the hardware, and operating systems are what translate application
software for the BIOS.

Answers

Answer:

Application software is what the user interacts with, and operating systems are what translate application software

Explanation:

The difference between the operating system and the software is that the application system has user interaction and the operating system has a translate application. Hence option B is correct.

Waht is a opering system  ?

An operating system is software that manages the computer hardware and software resources and also provides the services to the computer program. The operating system works on the basis of time-sharing and schedules the tasks for efficient allocation of time.

The application software is based on the application that is developed by the company such as Microsoft or adobe.

Find out more information about the operating system.

brainly.com/question/1763761

Which of these jobs would be most appropriate for someone who majors in information systems?

Answers

Answer:

An Architect, System Designers, IT business analysts etc...

Explanation:

Answer:An Architect and System Designers someone who studies complex work

Explanation:

10 points
What is wrong with the following code:
(don't say syntax error, what is the wrong)
>>> print 'Hello world!'
File " primt 'Hello world!'
SyntaxError: invalid syntax

Answers

Answer:

Primt

Explanation:

You work for a company that is losing sales because it takes days to manufacture products. What technology can you suggest the company use to speed production? A. commercial virtual reality B. telecommuting C. computer-aided manufacturing D. automated vehicles

Answers

Answer:

The correct answer is option C. computer-aided manufacturing.

Explanation:

Computer-aided manufacturing (or CAM for short) is the use of numerical control (NC) software applications with the aim of creating detailed instructions (G code) that drive computer numerical control machine tools ( CNC) for fabrication parts. Manufacturers in many different industries rely on CAM capabilities to produce high-quality parts.  

A broader definition of CAM may include the use of computer applications to define a manufacturing plan for tool design, computer aided design (CAD), model preparation, NC programming, inspection programming coordinate measuring machines (CMM), machine tool simulation or post-processing. The plan is then executed in a production environment, such as direct numerical control (DNC), tool management, CNC machining, or CMM execution.

what are super computers? what is their application in real life situation​

Answers

Answer:

A supercomputer is a computer with a high level of performance as compared to a general-purpose computer. Common applications for supercomputers include testing mathematical models for complex physical phenomena or designs, such as climate and weather, evolution of the cosmos, nuclear weapons and reactors, new chemical compounds (especially for pharmaceutical purposes), and cryptology.

A _____ describes two or more computers connected to each other.

computer network

client

server

switch

Answers

Answer:

C

Explanation:

computer network

what is you full name ?​

Answers

Answer:

Name: Whydoyouneedtoknow

Answer: Deshawn Reshawn Burgess

Explanation:

My full name

Which correctly lists the two elements that make up the empty space in the universe? ice and debris debris and dark matter dark matter and dark energy dark energy and dust

Answers

Answer:

The answer is "dark matter and dark energy and dust".

Explanation:

In the empty room, the universe is gases and ashes. Even though humans think the exterior universe's blank space is nothing more than empty.  Fortunately, the plasma form of its hydrogen and helium gases, including the various types of dirt and debris, occupy this void vacuum.  There are also several other materials however these greenhouse gases and dust particles are also the bulk of the material.

Answer:

c

Explanation:

Why does a business need to use effective strategies to find a solution for a problem?
- to thoroughly understand the problem
-to find several solutions to a problem
-to properly diagram the flow of information to solve the problem
- to find a solution that cannot be replicated​

Answers

Answer:

to properly diagram the flow of information to solve the problem

Explanation: 99% sure this is it

A business needs to use effective strategies to find a solution for a problem for several reasons. First, using effective strategies can help the business thoroughly understand the problem they are trying to solve.

What is business?

Business refers to an organization or an individual engaged in commercial, industrial, or professional activities with the aim of generating profit.

A business typically involves buying or producing goods or services and selling them for a profit to consumers or other businesses.

For a number of reasons, a firm has to adopt efficient methods to resolve a problem. First, employing successful tactics can aid a company in fully comprehending the issue at hand, as well as its underlying causes, potential effects, and potential solutions.

This may result in more focused and successful attempts to solve problems.

Second, excellent tactics can assist the company in locating and assessing a number of potential fixes for the issue, enabling them to select the ideal course of action in light of their particular requirements and circumstances.

Thus, finding a solution that can be replicated is often desirable, as it can help the business avoid similar problems in the future and streamline their operations.

For more details regarding business, visit:

https://brainly.com/question/15826604

#SPJ2

Using the flowchart below, what value when entered for Y will generate a mathematical error and prevent our flowchart from being completely executed? 3 0 1 None of these values will produce a mathematical error

Answers

Answer:

The answer is the last choice that is "None of these values will produce a mathematical error".

Explanation:

In this question, the above given choice correct because neither of the flowchart procedures could trigger a mathematical error. This error could not be induced by multiplication, addition and subtraction, and the only division by 15. It is the only divide by 0, that's why the above flowchart will produce a mathematical error.

Should the use of hacktivists by a country against enemy organizations be considered an act of war? Why or why not? How about the use of cyberterrorists?

Answers

Explanation:

Hacktivist comes from the combination of two words --- "Hack" and " Activism" .

Hacktivist perform hacktivism that means they make use of technology and knowledge to support as well as promote the political agenda and any kind of change in the social event.

Cyberterrorism, on the other hand uses internet and technology and conduct terrorism and other anti national activities like to coerce the societies or the governments in pursuit of their goals which are  religious, ideological or political.

While Hacktivism is used for a political cause, and is done in a peaceful manner; whereas cyber terrorism tries to grab the attention of the public through their aggressive ways, specifically by putting fear among the public.

But there is no instance of any person of getting killed by a cyber-attack or cyber terrorism. The larger damage is however done by those viruses or malware which gets into other persons computers or enemy organization computer system and weakens them and steals information and data. They damage and harm the economy in a larger scale.

When Chinese government first introduced the Trojan virus on the computer systems of their opponents abroad, is that can be called as Hacktivism? In  essence, this act may be called as cyber terrorism and not hacktivism. Because the Chinese Government intend to cause major economic damage and harm to their opponents or enemy organization by targeting the software giants in the West.

These companies crashed and and many left jobless and unemployment, they caused economic problems and damage to the technologies.  However, the Chinese Government's perspective on this is that they addresses such a thing as hacktivism as it advocates the state censorship by filtering the politically or the socially-unacceptable ideas in their e-mail.

Thus, the answer is relative as to whose perspective we are looking. Either we are taking the perspective of the Chinese government or that of the enemy organization which is affected by the act of the state censorship and targeting the Western software giants.

Cyberterrorism will somehow become a serious threat to the society when people adept at hacking will sympathize and also align with terrorists activities and cause. It has become appealing since some of computer programs have the features that are easily exploited and conducive for committing cyber terrorism.

If you were to conduct an Internet search on vegetarian restaurants, which of the following searches would be the best
to use?
'vegetarian restaurants
"restaurants
"vegetarians"
all of these

Answers

Answer:

A.

Explanation:

just did it

you really need to ask brainly for this question? obviously its vegetarian restaurants

What is the greatest common
factor of the following three
numbers?
12, 18, 32​

Answers

Answer: 2

Explanation:

What were precomputed tables and why were they necessary?​

Answers

Yesterday’s comment is a good idea to have you on in your life if I can find a good job in the world of the control you can get in your life if you’re a real life or you can get your own job

Precomputation in algorithms refers to the act of running an initial computation ahead of run time to create a lookup table that may be used by an algorithm to avoid running the same computation repeatedly each time it is executed.

What is algorithm?

An algorithm is a process used to carry out a computation or solve a problem. In either hardware-based or software-based routines, algorithms function as a detailed sequence of instructions that carry out predetermined operations sequentially.

Algorithms are procedures for resolving issues or carrying out tasks. Algorithms include math equations and recipes.

Algorithms are used in programming. All online searching is done using algorithms, which power the internet.

The term "precomputation" in the context of algorithms refers to the act of performing an initial computation before the algorithm is actually used.

This creates a lookup table that the algorithm can utilise to avoid performing the same computation repeatedly each time it is used.

Thus, this way, precomputed tables are essential.

For more details regarding algorithm, visit:

https://brainly.com/question/22984934

#SPJ2

Multiple Choice
Which of the programs below will result in the following output?
Hours
8
85
10
Total
26.5

Answers

Answer:

print("Hours")

print(8)

print(8.5)

print(10)

print("Total")

print(8 + 8.5 + 10)Explanation:

Answer:

A

Explanation:

choose the types of work a person in the network systems administration field might go on a regular basis. check all boxes that apply
A. troubleshooting the network when there are problems with connectivity.
B. improving the speed of the network.
C. helping users install word-processing software.
D. developing video games​

Answers

Answer:troubleshooting the network when there are problems with the connectivity |||||| improving network speed

Explanation:

What is the purpose of the Chart feature in Word?
O A chart can be used to draw and format a Word table.
O A chart can be used to paste information from a graph.
O Information can be typed into a chart to create a graph.
O Information can be typed into a chart to insert a Word table.

Answers

Answer:

Its the third option.

Explanation:

Answer: its c Information can be typed into a chart to create a graph

Explanation:

Other Questions
A student has a part time job in which she works 4 hour shifts. Her pay scale is $5.25 hour. How many shifts must she work to earn $220? How can I read this correctly What is the equation shown in standard form of the line shown on the graph?O x = 4O y = 4O x - y = 4 -7y + 3 12 2yWhat is the answer Conversion Practice: Find the equivalent binary or decimal numbers below. Binary Decimal Binary Decimal 100 5 101 17 1101 63 0001 1111 64 0010 0000 127 1010 1010 256 1111 1111 513 The table shows the total cost, p, for renting a playroom for a birthday party with c party guests. Number of Party Guests (C) Total Cost (p), in Dollars 3 274 7 306 12 346 21 418 Which of the following equations represents the input/output table using function notation? O A. p = 8c + 250 O B. p = 258c C. f(c) = 8c + 250 O D. f(p) = 8c - 250 Employers prefer to hire someone who has been referred to them, rather than a complete stranger. Who doesnt have to follow religious laws according to judeo christian tradition? If a triangle is an equilateral triangle, then the triangle has exactly three 60 angles. ABC is an equilateral triangle? Diffusion of policies relates to which advantage of federalism? On January 2, 20X1, Meister Company issues $200,000 of 6% bonds. Interest of $6,000 is payable semi-annually on June 30 and December 31. The bonds mature in 5 years. The market yield for bonds of similar risk and maturity is 7%. Utilizing the time value of money tables in your book, calculate the issue price of the bonds (round the result to whole dollars). Un volcan lanza una roca con una rapidez de 47.5 m/s con un angulo de 39.4 sobre el eje x. La roca toca el suelo a 1750 m por debajo de la altura inicial si se desprecia la resistencia del aire y considerando un valor constante de aceleracion debido a la gravedad de 9.81 m/s2 cual es el tiempo en completar la trayectoria How to reflect the triangle below across the line y = x. What is an algebraic expression for "2 less than the product of 3 and a number x"? * Match the scientist to his contribution to the atomic theory - Thomson - Rutherford - Bohr A. Electron energy levels B. Nucleus C. Electrons Which figure is described below? Based on what you just read about the murder of John Hossack, what can you predict about the events that will take place in the play Trifles? One of the fundamental questions asked by virtue ethicists is________. Explanation & Process Needed The average of a set of 6 numbers is 3.5. If the number 4.2 is added to the set, what is the average of the new set of numbers?