⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter5n9.java

📁 JAVA源代码程序aashjkjhkjhkjhjkhkj
💻 JAVA
字号:
/** * * demonstration of nested loops (further modified inner loop - test version) * * Written by: Roger Garside * * First Written: 12/June/96 * Last Rewritten: 2/Oct/96 * */import java.lancs.* ;public class Chapter5n9    {    /**     *     * 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 ;	    boolean duplicateFound = false ;	    System.out.println("TEST: starting inner loop: count=" +						computing.getCount()) ;	    while ((i < computing.getCount()) && (!duplicateFound))	        {	        System.out.println("TEST: start inner iteration: i=" + i) ;		if (s.equals(computing.getSurname(i)))		    duplicateFound = true ;                i++ ;	        System.out.println("TEST: finish inner iteration: i=" + i) ;	        }	    System.out.println("TEST: leaving inner loop: i=" + i) ;            if (!duplicateFound)	        {	        // 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 Chapter5n9

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -