正在加载图片...
Loop Control with Boolean variable boolean repeat true; sum =0 num nputBox. getInteger ( if(num == 0) //sentinel message Box. show("Sum sum) repeat falser else if(num号2==0) //invalid data Terminates the message Box. show("Error: even number was entered") loop by setting the boolean repeat false variable to false else t sum += num if(sum> 1000)( //pass the threshold message Box. show("Sum became larger than 1000")i repeat false while( repeat )i C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 7-17© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 7 - 17 Loop Control with Boolean Variable boolean repeat = true; sum = 0; do { num = inputBox.getInteger(); if (num == 0) { //sentinel messageBox.show("Sum = " + sum); repeat = false; } else if (num % 2 == 0) { //invalid data messageBox.show("Error: even number was entered"); repeat = false; } else { sum += num; if (sum > 1000) { //pass the threshold messageBox.show("Sum became larger than 1000"); repeat = false; } } } while ( repeat ); Terminates the loop by setting the boolean variable to false
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有