Sort by

recency

|

274 Discussions

|

  • + 0 comments
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
           
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int[] a = new int[n];
         for(int i=0;i<n;i++)
         {
              a[i]=scan.nextInt();
         }
            scan.close();
    
            // Prints each sequential element in array a
            for (int i = 0; i < a.length; i++) {
                System.out.println(a[i]);
            }
        }
    }
    
  • + 0 comments

    Practicing mapping:

            //java8
            ArrayList<Integer> A = new ArrayList<>();
            while (scan.hasNextInt())A.add(scan.nextInt());
            int[] a = A.stream().mapToInt(i -> i).toArray();
    
  • + 0 comments

    In java 8:

    int[] a = new int[n]; for (int i =0; i < n; i++) { a[i] = scan.nextInt(); }

  • + 0 comments

    int a[]=new int[n];

        for(int i=0;i<a.length;i++){
        int b=scan.nextInt();
        a[i]=b;
        }
    
  • + 0 comments

    int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = scan.nextInt(); }

                this works!!