📄 chapter5n7.java
字号:
/** * * demonstration of nested loops (test version) * * Written by: Roger Garside * * First Written: 12/June/96 * Last Rewritten: 2/Oct/96 * */import java.lancs.* ;public class Chapter5n7 { /** * * main * */ public static void main(String[] args) throws Exception { GroupOfPeople computing = new GroupOfPeople() ; String s ; while (true) { System.out.println("Type a surname followed by 'return'") ; System.out.println("(type 'return' when there are no more surnames)") ; s = BasicIo.readString() ; if (s.length() == 0) break ; // explanation start HERE int i = 0 ; System.out.println("TEST: starting inner loop: count=" + computing.getCount()) ; while (i < computing.getCount()) { System.out.println("TEST: start inner iteration: i=" + i) ; if (s.equals(computing.getSurname(i))) break ; i++ ; System.out.println("TEST: finish inner iteration: i=" + i) ; } System.out.println("TEST: leaving inner loop: i=" + i) ; if (i == computing.getCount()) { // search did not find a match computing.addSurname(s) ; System.out.println("inserted surname " + s) ; } else { // search did find a match System.out.println("WARNING: surname " + s + " duplicated") ; System.out.println("not added to the list") ; } // explanation finishes HERE } System.out.print("There are " + computing.getCount()) ; System.out.println(" people in the group") ; for (int i = 0 ; i < computing.getCount() ; i++) { System.out.print("The " + (i + 1) + "th surname is ") ; System.out.println(computing.getSurname(i)) ; } } // end of method main } // end of class Chapter5n7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -