fork download
  1. class Kadai{
  2. public static void main(String[] mes){
  3. int[] a = {5,-1,3,4,-2,7};
  4.  
  5. int count =0;
  6.  
  7. for (int i=0;i<a.length; i++)
  8. if (a[i]>0)
  9. count++;
  10.  
  11. int[] b =new int[count];
  12.  
  13. int j =0;
  14. for (int i=0; i<a.length;i++)
  15. if(a[i]>0)
  16. b[j++]=a[i];
  17.  
  18. /*ここから下は確認用なので提出する前に消すこと*/
  19. System.out.println("aの配列");
  20. for (int i=0; i<a.length;i++)
  21. System.out.print(String.valueOf(a[i]) + " ");
  22. System.out.println("\nbの配列");
  23. for (int i=0; i<b.length;i++)
  24. System.out.print(String.valueOf(b[i]) + " ");
  25. }
  26. }
Success #stdin #stdout 0.02s 245632KB
stdin
Standard input is empty
stdout
aの配列
5 -1 3 4 -2 7 
bの配列
5 3 4 7