id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2022_10_13_P1SLHL_makeNumSigned
prev  |  next  |  chance

Write a method that accepts a Boolean ‘neg’ and three single-digit non-negative integers, 'hundreds', 'tens', and 'ones'. Each of these integer parameters contains a single non-negative digit that represents a place-value in a base 10 number (the kind of numbers you have been using your whole life). If the parameter ‘neg’ is true you are making a negative number. If ‘neg’ is false you are making a positive number. Return a single integer value that is equal to the value represented by these place-value digits and has the sign indicated by the value of ‘neg’. For example, if ‘neg’ is true, 'hundreds' is 5, 'tens' is 2, and 'ones' is 7, that means we are trying to represent the number -527, so return that value. As preconditions, you may assume that each of the parameters only contains a single digit 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. Note: If leading digits are zeros, those digits will not appear in the final answer. For example, if ‘neg’ is false, 'hundreds' is 0, 'tens' is 0, and 'ones' is 5, you will just return the value 5. If 'hundreds' is 0, 'tens' is 3, and 'ones' is 1, you will return the value 31. Look at the test data for further examples.


test2022_10_13_P1SLHL_makeNumSigned(false, 5, 3, 1) → 531
test2022_10_13_P1SLHL_makeNumSigned(true, 8, 0, 2) → -802
test2022_10_13_P1SLHL_makeNumSigned(true, 0, 0, 0) → 0

...Save, Compile, Run (ctrl-enter)

public int test2022_10_13_P1SLHL_makeNumSigned(Boolean neg, int hundreds, int tens, int ones) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 240

Copyright Nick Parlante 2017 - privacy