29 lines
1023 B
Java
29 lines
1023 B
Java
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
*/
|
|
package lab11_calebfontenot;
|
|
|
|
import java.util.Scanner;
|
|
|
|
/**
|
|
*
|
|
* @author caleb
|
|
*/
|
|
public class WhileEvent1 {
|
|
public static void main(String[] args) {
|
|
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
|
Scanner scan = new Scanner(System.in);
|
|
int num = scan.nextInt(); //2 Condition: initialize the condition of the loop
|
|
int sum = 0; //1 task: Initialize the task
|
|
while (num != -1) //1 condition: What is the condition?
|
|
{
|
|
sum += num; //2 task: task of the loop and its update
|
|
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
|
num = scan.nextInt();//3 condition update the condition of the loop.
|
|
}
|
|
|
|
System.out.println("Total " + sum);
|
|
}
|
|
}
|