1String s[]= scanner.nextLine().split(" ");for(int i =0 ;i < s.length;i++){ a[i]= Integer.parseInt(s[i]);}
1 Scanner scanner = new Scanner(System.in);
2 int numOfBlocks = scanner.nextInt();
3 int weightArray[] = new weightArray[numOfBlocks];
4 for(int i=0;i<numOfBlocks;i++)
5 {
6 weightArray[i] = scanner.nextInt();
7 }
8 scanner.close();
9//your logic
1import java.io.BufferedReader;
2import java.io.IOException;
3import java.io.InputStreamReader;
4
5class BufferedReaderTest
6{
7 public static void main(String[] args) throws IOException {
8 BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
9
10 int num[] = new int[1000];
11 String[] strNums;
12 long startTime, endTime;
13
14
15 /*________ TEST STARTS ________*/
16 startTime = System.nanoTime();
17 strNums = bi.readLine().split("\\s");
18 for(int i=0; i<strNums.length; i++) {
19 num[i] = Integer.parseInt(strNums[i]);
20 }
21 endTime = System.nanoTime();
22 /*________ TEST ENDS ________*/
23
24 System.out.println("Total Time Taken: " + (endTime - startTime));
25 }
26}
27
1# if you read from console
2
3 Scanner scanner = new Scanner(System.in);
4 List<Integer> list = new ArrayList<Integer>();
5 while (scanner.hasNextInt())
6 list.add(scanner.nextInt());
7 int[] arr = list.toArray(new int[0]);
8
9# if you read from file
10
11 try {
12 File myObj = new File("filename.txt");
13 Scanner myReader = new Scanner(myObj);
14 while (myReader.hasNextInt()) { // check for next integer in file
15 String data = myReader.nextInt(); // read the integer
16 System.out.println(data);
17 }
18 myReader.close();
19 } catch (FileNotFoundException e) {
20 System.out.println("An error occurred.");
21 e.printStackTrace();
22 }