Skip to content

Instantly share code, notes, and snippets.

@ajaybgupta
Created November 29, 2017 03:16
Show Gist options
  • Save ajaybgupta/f8b5e93f08cddeb10314e02e9b1a6232 to your computer and use it in GitHub Desktop.
Save ajaybgupta/f8b5e93f08cddeb10314e02e9b1a6232 to your computer and use it in GitHub Desktop.
Hacker Rank - Reading Input Data
def simpleArraySum(n: Int, ar: Array[Int]): Int = {
ar.sum
}
def main(args: Array[String]) {
val sc = new java.util.Scanner (System.in);
var n = sc.nextInt();
var ar = new Array[Int](n);
for(ar_i <- 0 to n-1) {
ar(ar_i) = sc.nextInt();
}
val result = simpleArraySum(n, ar);
println(result)
}
@ajaybgupta
Copy link
Author

To read string directly from screen
val s = sc.next()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment