Question

I am having trouble with this as I am a beginner: This program should have a...

I am having trouble with this as I am a beginner:

This program should have a main function.
3. The program should also have another function called“RoundFunct” and this function should round up or round down a double value to an integer value.
4. Rules: Cannot use round function

  • For positive values
    • Round up a value if its fraction part is greater or equal to “.5”
    • Round down a value if its fraction part is less than “.5”
  • For negative values
    • Round down a value if its fraction part is greater or equal to “.5”
    • Round up a value if its fraction part is less than “.5”

5. Examples

  • 0.4 should be rounded down to 0
  • 0.6 should be rounded up to 1
  • -0.4 should be rounded up to 0
  • -0.6 should be rounded down to -1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

source code:

import java.util.Scanner;
public class round
{
public static void main(String...args)
{
Scanner in=new Scanner(System.in);
double input=in.nextDouble();
  
System.out.println(RoundFunc(input)); //calling function
}
  
static int RoundFunc(double input)
{
int x=(int)input; //type casting
int temp=0;
if(input>=0) //input is positive number
{
double y=x+0.5; //calculating y value and compare with input
if(y<input)
temp= x+1;
else if(y>=input)
{
temp= x;
}
}
  
  
else if(input<0) //input is negitive number
{
double y=x-0.5; //compare y value with input and swap
if(y<input)
temp= x;
else if(y>=input)
{
temp= x-1;
}
}
return temp;} //return temp;
  
}
  

Add a comment
Know the answer?
Add Answer to:
I am having trouble with this as I am a beginner: This program should have a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to program a dice game in Visual Studios c++ but am having trouble....

    I am trying to program a dice game in Visual Studios c++ but am having trouble. The program allows the user to choose the number of rolls, not exceeding 100,000. I am trying to print out the number of times each number(1-6) was rolled, but it's not working. What am I doing wrong? The link below is a copy of my code. https://docs.google.com/document/d/1baKfnof4pjdQ4905hwXluFtbcA1Fs7QESMQKy45xdpE/edit

  • I'm having a little bit of trouble and not sure If I am entering it right...

    I'm having a little bit of trouble and not sure If I am entering it right on my calculator. I put 2nd--> VARS--> normalCDF lower: -1E99 upper: z score and pressing enter Whenever I do this, it says I am wrong. Please help! Using a TI-84 calculator, find the area under the standard normal curve to the left of the following z-values. Round the answers to four decimal places. Part 1 of 4 is .35171x The area to the left...

  • I am having trouble figuring out what should go in the place of "number" to make...

    I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as...

  • I have been looking over and interpreting some sample code and am having some trouble understanding...

    I have been looking over and interpreting some sample code and am having some trouble understanding what is going on with a bit of slicing syntax. For some context I am working on a computational program that uses method of finite differences approximating temperatures over a square region. Here is some of the code: maxIter = 500 lenX = lenY = 20 delta = 1 Ttop = 100 Tbottom = 0 Tleft = 0 Tright = 0 Tguess = 30...

  • I have completed Machin's formula, but I am having trouble with the other two. This is...

    I have completed Machin's formula, but I am having trouble with the other two. This is because the code's for Leibniz's formula and Ramanujan's formula need to be done using loops not syssum or things like that. PLEASE HELP! Since the advent of computers, a large number of digits of π has been available. However, before that, many mathematicians found ways to approximate T. For example Machin's formula (1706) is 4 arctan - arctan Leibniz (~1750) found that π can...

  • Hi, I am having trouble with using the matplotlib function in python. A tutorial in this...

    Hi, I am having trouble with using the matplotlib function in python. A tutorial in this question and a lesson on how to use it would be great. Thanks so much. 2- Write a program using matplotlib that gives the following output Consider 100 points between [0,10] Fiqure 1 10 8 10 #Your program here:

  • Hello everyone! I am working on my assignment for C++ and I'm having a bit of...

    Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...

  • Here is what i have so far... However i am having a little bit of trouble...

    Here is what i have so far... However i am having a little bit of trouble with it. when inputting a number the sum comes out perfect but when i break the digits up i cant do mmore than 4 digits and i cant do a negitive number... someone help. QUESTION: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example,...

  • I have this c++ program that i have to create but i am stuck on it....

    I have this c++ program that i have to create but i am stuck on it. Write a height conversion program that shall allow user to convert from feet and inches to meters (option 1) and vice versa (option 2). User shall be able to specify the type of conversion (a menu of two options). Display an error message if an invalid option is specified. Otherwise, the program would read in a length in feet and inches (two separate integer...

  • I am having trouble with part B, i have done the other two parts. I know...

    I am having trouble with part B, i have done the other two parts. I know how to find the transition matrix when i have basis in the form of B = {(_ _ _), (_ _ _), (_ _ _)} but not one like this. Thanks so much for your help! Let V be the vector space of solutions to the ODE y" - 3y' +2y 0, with basis given by β-fet, e,2), and let z,-2et-e2t and z,-c"-et. (a)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT