WhileLoopWithBreak

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

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

View Full Document Right Arrow Icon
//While loop with the break statement import java.util.*; i public class WhileLoopWithBreak { static Scanner console = new Scanner(System.in); s public static void main (String[] args) { int num; int sum; i sum = 0; s System.out.print("Enter positive integers: "); S while (console.hasNext())
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 { System.out.println("Negative number found in the data."); break; } sum = sum + num; } System.out.println(); System.out.println("The sum is: " + sum); } }...
View Full Document

Ask a homework question - tutors are online