WhileLoopAndContinue - 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 and the continue statement / import java.util.*; i public class WhileLoopAndContinue { 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, go to the next iteration { System.out.println("Negative number found in the data."); continue; } sum = sum + num; } System.out.println(); System.out.println("The sum is: " + sum); } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online