Java: How to use Command Line Arguments to add integers in a text file? -


i need use clas control adding of integers in file. first argument number of integers add. second arg other line skip when adding them( 3 2 should output 72 because adds 3 integers whilst skipping every 2nd line. text file

7 16 55 4 10    

i need on how implement int m in code skips specified line.

    int n = integer.parseint(args[0]);     int m = integer.parseint(args[1]);       (int = 0; < n; i++) {              x = in.next();              sum = sum + integer.parseint(x);      }       system.out.println(sum); 

what store numbers until n*m in array. easier way since can iterate , sum of numbers incrementing n

something this:

int count = 0, sum = 0; (int = 0; < num.length && count < m; += n) {     sum = sum + integer.parseint(num[i]);     count++; } 

with 2 2 -> sum = 62 , 3 2 -> sum = 72

demo. tried simulate trying without reading file using online ide.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -