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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 2개는 보이지 않습니다)
9번째 줄: 9번째 줄:
----
----


<source lang='java'>
<syntaxhighlight lang='java'>
</source>
import java.util.*;
<source lang='java'>
public class Main{
</source>
  static Iterator func(ArrayList mylist){
<source lang='java'>
      Iterator it=mylist.iterator();
</source>
      while(it.hasNext()){
</syntaxhighlight>
<syntaxhighlight lang='java'>
        Object element = it.next();
        if(element instanceof String)
</syntaxhighlight>
<syntaxhighlight 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);
      }
  }
}
</syntaxhighlight>

2020년 11월 2일 (월) 02:51 기준 최신판

개요[ | ]

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 }}