Respuesta :

import java.util.Scanner;

public class PosNums {

   public static void main(String[] args) {

       System.out.println("Enter positive numbers (-1 to stop)");

       Scanner myObj = new Scanner(System.in);

       int num = myObj.nextInt();

       int total = 0;

       while (num!=-1){

           if (num < 0 && num!= -1){

               System.out.println("Only positive numbers will be counted toward your total.");

           }

           else if (num >=0){

               total += num;

           }

           num = myObj.nextInt();

       }

       System.out.println("Sum is " + total);

   }

   

}

If you have any other questions, I'll do my best to help. Best of luck.

Otras preguntas