how to make a cycle or loop that adds up an amount until it is positive

1

My doubt is like doing a cycle or loop that adds up a quantity hasta que sea positiva

Example:

-870+360 = -510

-510+360= -150

-150+360 = 210

and only shows the positive result ie 210 in the example

    
asked by Liantony Pozo 08.04.2017 в 23:27
source

2 answers

0

You can do it using a while and using the operator + =, resulting in 210 :

    int valor = -870;
    while(valor < 0){
      valor+= 360;    
    }

   System.out.println("valor resultante : " +  valor);

having as output:

valor resultante : 210
    
answered by 08.04.2017 / 23:37
source
0
x=valor_inicial;
for (i=valor_inicial;i<=0;i+=360){
x=i;
}
    
answered by 08.04.2017 в 23:37