title: I have a Java homework problem that I cannot seem to figure out. Using regular expression and/or API classes like Pattern, Matcher is not allowed
body: <p>//Name this program StuPreIPv6) Each network device must be assigned an IP address. An IPv6 (IP address version 6) address is represented in the preferred format as eight groups of four hexadecimal digits. A hexadecimal digit may be 0 ~ 9 or a ~ f (or A ~ F). The groups are separated by colons (:). An example of an IPv6 address is:</p>
  <pre><code>2001:0db8:85a3:0000:0000:8a2e:0370:7001
  </code></pre>
  <p>Write a method to decide whether a string contains a valid IPv6 address in the preferred format (each h represents a hexadecimal digit):</p>
  <p>hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh</p>
  <p>For this assignment, your method must loop through individual characters in the string. Approaches using regular expression and/or API classes like Pattern, Matcher will receive zero credit.</p>
  <p>Start with a method stub like this one. The main() will be used for unit testing (see ch6.6).</p>
  <p>// Returns true if the string parameter contains a valid IPv6
  // address in the preferred format. Otherwise returns false.</p>
  <pre><code>public class IPv6{ 
       public static boolean isValidPreferFormatIpv6(String address) {
       return false;
    }
    
    // for unit testing
      public static void main(String[] args) {
          System.out.println(&quot;Testing started ...&quot;);
      
      String str; // store test strings
      
      str = &quot;&quot;;
      if (isValidPreferFormatIpv6(str) != false) // if not the expected result
        System.out.println( &quot;isValidPreferFormatIpv6(&quot; + str + &quot;) failed&quot;; 
  
      str = &quot;0123:4567:89ab:cdef:0123:4567:89ab:cdef&quot;;
      if (isValidPreferFormatIpv6(str) != true) // if not the expected result
       System.out.println( &quot;(isValidPreferFormatIpv6(&quot; + str + &quot;) failed&quot;; 
    
  // add more testing cases    
  
  
      System.out.println(&quot;Testing completed.&quot;);public class IPv6{ 
       public static boolean isValidPreferFormatIpv6(String address) {
       return false;
    }
    
    // for unit testing
      public static void main(String[] args) {
          System.out.println(&quot;Testing started ...&quot;);
      
      String str; // store test strings
      
      str = &quot;&quot;;
      if (isValidPreferFormatIpv6(str) != false) // if not the expected result
        System.out.println( &quot;isValidPreferFormatIpv6(&quot; + str + &quot;) failed&quot;; 
  
      str = &quot;0123:4567:89ab:cdef:0123:4567:89ab:cdef&quot;;
      if (isValidPreferFormatIpv6(str) != true) // if not the expected result
       System.out.println( &quot;(isValidPreferFormatIpv6(&quot; + str + &quot;) failed&quot;; 
    
  // add more testing cases    
  
  
      System.out.println(&quot;Testing completed.&quot;);
      
  </code></pre>