WhileLoopWithOutBreak

WhileLoopWithOutBreak - { num = console.nextInt(); n if...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//While loop without the break statement / import java.util.*; i public class WhileLoopWithOutBreak { static Scanner console = new Scanner(System.in); s public static void main (String[] args) { int num; int sum; i boolean isNegative; sum = 0; isNegative = false; System.out.print("Enter positive integers: "); S
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { num = console.nextInt(); n if (num < 0) //if number is negative, terminate the loop //after this iteration { System.out.println("Negative number found in the data."); isNegative = true; } else sum = sum + num; } System.out.println(); System.out.println("The sum is: " + sum); } }...
View Full Document

Ask a homework question - tutors are online