# Re-type the code and fix any errors. the code should convert non-positive numbers to 1.

171 views

## Problem:

Hello all,
I am a noob to this java programming. I started learning it a few days back. Re-type the code and fix any errors. the code should convert non-positive numbers to 1. As long as I understand this problem is sying to convert a negative number to positive. So, I am struggling with a problem like converting a negative number to 0 or 1 in my program. I’ve got a shallow concept in my mind but that’s not enough for my case. If your understanding is up to this level, please pull me up from the grave LOL.

Thanks.

## Solution:

Hello Gavin,

You’ve asked an interesting but very basic question. No shame! I appreciate your asking. You can solve this problem by using an if-statement in your program. If-else will check your number and then return it as you wanted. Let’s start:

``````public class NegToPos {
public static void main (String [] args) {
int Num = 0;
if (Num >= 0)
System.out.println("It's a non negative number");
else{
System.out.println("It's a negative nummber; now converting to 1");
Num = 1;
System.out.format("Final: %d", Num);
System.out.println("");
}
}
}``````

So, this code should convert non-positive numbers to 1. Thanks again. Keep asking. ## Related questions

343 views
Problem : I am facing issues with following Java code and unable to figure out the cause behind the issue, I guess it is some logical error but I am unable to figure it out, my all results are ending up as 0. Please find below the Java Code: import java.util.Scanner; ... out.format("Final Result: %d", myUserNum); System.out.println(""); return; } } Please let me know how can I fix this issue?
112 views
Problem : I am very new to r programming. I have the array and I want to implement the below method: x<-function(b){ if (b>0){ b/sum(b) } else 1 } This method is written to check if there is any value which is larger than the 0 and if it says ... message: &ldquo;Warning message: r the condition has length > 1 and only the first element will be used&rdquo;. How can I fix the above error message?