"HR자바 Java Iterator"의 두 판 사이의 차이

10번째 줄: 10번째 줄:


<source lang='java'>
<source lang='java'>
import java.util.*;
public class Main{
  static Iterator func(ArrayList mylist){
      Iterator it=mylist.iterator();
      while(it.hasNext()){
</source>
</source>
<source lang='java'>
<source lang='java'>
        Object element = it.next();
        if(element instanceof String)
</source>
</source>
<source lang='java'>
<source lang='java'>
        break;
      }
      return it;
  }
  @SuppressWarnings({ "unchecked" })
  public static void main(String []args){
      ArrayList mylist = new ArrayList();
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      for(int i = 0;i<n;i++){
        mylist.add(sc.nextInt());
      }
     
      mylist.add("###");
      for(int i=0;i<m;i++){
        mylist.add(sc.next());
      }
     
      Iterator it=func(mylist);
      while(it.hasNext()){
        Object element = it.next();
        System.out.println((String)element);
      }
  }
}
</source>
</source>

2018년 8월 15일 (수) 00:56 판

개요

HR자바 Java Iterator
해커랭크 Java
# 문제 비고
HR자바 Object Oriented Programming e
43 HR자바 Java Inheritance I
44 HR자바 Java Inheritance II
45 HR자바 Java Abstract Class
46 HR자바 Java Interface
47 HR자바 Java Method Overriding
48 HR자바 Java Method Overriding 2 (Super Keyword)
49 HR자바 Java Instanceof keyword
50 HR자바 Java Iterator

import java.util.*;
public class Main{
   static Iterator func(ArrayList mylist){
      Iterator it=mylist.iterator();
      while(it.hasNext()){
         Object element = it.next();
         if(element instanceof String)
         break;
      }
      return it;
   }
   @SuppressWarnings({ "unchecked" })
   public static void main(String []args){
      ArrayList mylist = new ArrayList();
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      for(int i = 0;i<n;i++){
         mylist.add(sc.nextInt());
      }
      
      mylist.add("###");
      for(int i=0;i<m;i++){
         mylist.add(sc.next());
      }
      
      Iterator it=func(mylist);
      while(it.hasNext()){
         Object element = it.next();
         System.out.println((String)element);
      }
   }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}