Skip to content

Instantly share code, notes, and snippets.

@ajayguptawork
Created November 29, 2017 03:16
Show Gist options
  • Select an option

  • Save ajayguptawork/f8b5e93f08cddeb10314e02e9b1a6232 to your computer and use it in GitHub Desktop.

Select an option

Save ajayguptawork/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)
}
@ajayguptawork

Copy link
Copy Markdown
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