Question
Asked Feb 8, 2020
8 views

In Ruritania, fractional numbers are rounded up to the next integer if the fractional part is at least 0.25. However, if they are negative, they are rounded down to the next lower integer if the fractional part is more than 0.75. For example,

2.5 → 3
2.25 → 3
2.24 → 2
-2.3 → -2
-2.76 → -3
-3.25 → -3

Complete the following program to print out the integer, using Ruritanian rounding.

No loops or if statements.

Numbers.java
2 import iava.util.Scanner;
ebook-bjeo-7-ch04-sec02_05-cc-2
4 public class Numbers
5 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
double x = in.nextDouble();
double rounded0 = Math.round ( (int) x);
9.
10
(int) rounded@;
int rounded
11
+ rounded);
System.out.println("Rounded:
}
12
13
14 }
help_outline

Image Transcriptionclose

Numbers.java 2 import iava.util.Scanner; ebook-bjeo-7-ch04-sec02_05-cc-2 4 public class Numbers 5 { public static void main(String[] args) { Scanner in = new Scanner(System.in); double x = in.nextDouble(); double rounded0 = Math.round ( (int) x); 9. 10 (int) rounded@; int rounded 11 + rounded); System.out.println("Rounded: } 12 13 14 }

fullscreen
check_circle

Expert Answer

Step 1: Java Source Code

import java.util.Scanner;

 

public class Numbers {

            public static void main(String args[])

            {

                        Scanner in=new Scanner(System.in);

                        double x=in.nextDouble();

                        double rounded0=Math.round(x);

                        int rounded=(int)rounded0;

                        System.out.println("Rounded:"+ rounded);

            }

}

 

Step 2: Screenshot of the Code

Computer Science homework question answer, step 2, image 1

...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Why does the data have to be transformed? What is being transformed? Explain the difference betwee...

A: Purpose of data transformation, and what is being transformed Data transformation is a technique of...

question_answer

Q: If we insert the entries (1,A), (2,B), (3,C), (4,D), and (5,E), in this order, into an initially emp...

A: Since initially the tree is empty, insert the first entry (1, A) as the root of the tree. Now the va...

question_answer

Q: Which of the following operating systems can be modified and the source code redistributed? Group of...

A: Open source code: The original source code of the open source software can be modified or redistrib...

question_answer

Q: Provide one advantage and one disadvantage for each of the database models.

A: Database Model can be described as an interconnected set of principles in an enterprise to represent...

question_answer

Q: What are features of Unified Communications Systems? How do they benefit the businesses that deploy ...

A: The unified Communication system is a type of business-class platform that combines all the latest d...

question_answer

Q: |(1st part) You are going to draw flowers a certain integral locations on a wall in your room. You h...

A: Program Instructions: In main method, call the function draw with length and location array.In funct...

question_answer

Q: I need help with #2 please

A: Given Code-#include <stdio.h>//declaring main functionint main(){    //declaring the variables...

question_answer

Q: Please help me withe the second function with the dynamic programming. And no loops allowed in the f...

A: Declare a global array and in main function initialize all its elements up to n to -1. Use a for loo...

question_answer

Q: Which of the following is a server dedicated to a specific software function, such as email or secur...

A: Definitions Application - This is a software or a computer program that runs on a computer. For exam...