Code example for Scanner

Methods: nextShort, useLocale

0
    /** 
     * @throws IOException 
     * @tests java.util.Scanner#nextShort(int) 
     */ 
    public void test_nextShortI() throws IOException { 
        s = new Scanner("123 456");
        assertEquals(123, s.nextShort(10));
        assertEquals(456, s.nextShort(10));
        try { 
            s.nextShort(10);
            fail("Should throw NoSuchElementException");
        } catch (NoSuchElementException e) {
            // Expected 
        } 
 
        // If the radix is different from 10 
        s = new Scanner("123 456");
        assertEquals(38, s.nextShort(5));
        try { 
            s.nextShort(5);
            fail("Should throw InputMismatchException");