Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Plus Minus in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
Advantages of Algorithms:
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Link for the Problem – Plus Minus – Hacker Rank Solution
Plus Minus– Hacker Rank Solution
Problem:
Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with places after the decimal.
Note: This challenge introduces precision problems. The test cases are scaled to six decimal places, though answers with absolute error of up to are acceptable.
Example
![Plus Minus in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 2 image 41](https://technorj.com/wp-content/uploads/2021/12/image-41.png)
0.400000 0.400000 0.200000
Function Description
Complete the plusMinus function in the editor below.
plusMinus has the following parameter(s):
- int arr[n]: an array of integers
Print
Print the ratios of positive, negative and zero values in the array. Each value should be printed on a separate line with digits after the decimal. The function should not return a value.
Input Format
The first line contains an integer, , the size of the array.
The second line contains space-separated integers that describe .
Constraints
![Plus Minus in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 3 image 43](https://technorj.com/wp-content/uploads/2021/12/image-43.png)
Output Format
Print the following lines, each to decimals:
- proportion of positive values
- proportion of negative values
- proportion of zeros
Sample Input
STDIN Function ----- -------- 6 arr[] size n = 6 -4 3 -9 0 4 1 arr = [-4, 3, -9, 0, 4, 1]
Sample Output
0.500000 0.333333 0.166667
Explanation
![Plus Minus in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 4 image 42](https://technorj.com/wp-content/uploads/2021/12/image-42.png)
Plus Minus – Hacker Rank Solution
import java.util.Scanner; /** * * @author Techno-RJ * */ public class PlusMinus { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int arr[] = new int[n]; float countPositive = 0; float countNegetive = 0; float countZero = 0; for (int arr_i = 0; arr_i < n; arr_i++) { arr[arr_i] = in.nextInt(); if (arr[arr_i] < 0) { countNegetive++; } if (arr[arr_i] > 0) { countPositive++; } if (arr[arr_i] == 0) { countZero++; } } System.out.printf("%1.6f \n", countPositive / n); System.out.printf("%1.6f \n", countNegetive / n); System.out.printf("%1.6f \n", countZero / n); in.close(); } }
order cialis female cialis cvs ed pills online
purchase duricef online cheap propecia brand where can i buy propecia
buy estradiol pills cost estradiol buy prazosin cheap
purchase fluconazole online cheap order generic diflucan 100mg buy generic cipro
buy mebendazole 100mg pill cost retin cream generic tadalafil
order flagyl 400mg for sale flagyl 400mg sale oral keflex 250mg
avanafil 200mg us order avana without prescription order diclofenac 50mg online cheap
clindamycin for sale order cleocin 150mg generic purchase fildena sale
order indocin 75mg online order suprax online cefixime medication
buy tamoxifen 10mg generic purchase budesonide generic buy ceftin medication
order amoxicillin 500mg for sale buy anastrozole 1 mg for sale biaxin ca
catapres 0.1 mg canada generic spiriva spiriva over the counter
careprost ca buy trazodone generic order desyrel 50mg generic
buy sildenafil 100mg sale buy sildalis without prescription sildalis generic
minocin 100mg sale actos order generic actos 15mg
purchase leflunomide without prescription cheap azulfidine 500mg order sulfasalazine pills
cialis 20mg uk sildenafil women cialis 40mg tablet
ivermectin for covid new ed drugs buy deltasone online cheap
order ramipril 10mg sale where to buy arcoxia without a prescription arcoxia 120mg cost
buy mesalamine buy azelastine 10ml generic order irbesartan 300mg for sale
benicar ca olmesartan 20mg cost order depakote 500mg pills
buy acetazolamide 250 mg pill isosorbide tablet order azathioprine 50mg without prescription
generic lanoxin 250mg order molnunat 200 mg generic brand molnunat 200 mg
order naproxen 250mg online cheap buy lansoprazole 15mg pill order lansoprazole 30mg online
albuterol 100mcg cheap how to buy albuterol purchase pyridium for sale
singulair for sale online order amantadine pills dapsone 100mg generic
buy nifedipine online cheap buy generic adalat 30mg fexofenadine canada