how to take space separated input in java

Java
 Scanner scanner = new Scanner(System.in);
 int numOfBlocks = scanner.nextInt();
 int weightArray[] = new weightArray[numOfBlocks];
 for(int i=0;i<numOfBlocks;i++)
       {
        weightArray[i] = scanner.nextInt();
       }
 scanner.close();
//your logicString s[]= scanner.nextLine().split(" ");for(int i =0 ;i < s.length;i++){    a[i]= Integer.parseInt(s[i]);}
Source

Also in Java: