Code example for Scanner

Methods: close, hasNext, next

0
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected 
        } 
 
        s = new Scanner("1'\n'2  ");
        assertEquals("1'", s.next());
        assertTrue(s.hasNext());
        assertEquals("'2", s.next());
        assertFalse(s.hasNext());
        // test boundary case 
        try { 
            s.next();
            fail("should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected 
        } 
 
        s = new Scanner("  ");
        assertFalse(s.hasNext());