Description
• Write a program that prints the sum of two selected numbers from a
line
– First line of input contains the number of lines to follow
– First number of each line, n>=4 and n<=1000, contains the number of
integers that follow in the line
– Those n integers (each integer >=0; <=1000) follow till the end of the line, and should be stored (except the last two) in an array using index
numbers 1…n-2
– The last two integers x, y (x,y>=1 & x,y<=n-2) in the line is the index
(starting from 1) of the integers from the line to sum up and print
Example: (colors are just for visualization):
Input:
3
5 13 2 5 1 3
6 5 8 6 7 4 2
9 2 12 7 14 5 17 9 6 3
Output:
18
15
24
Input/output in Java
• Use Standard I/O to read input and write the result
• For Java, input: System.in, output: System.out
• To read numbers, one option is:
• Use a single Scanner object
Scanner sc = new Scanner(System.in);
• Use nextInt()over and over to read integers
number = sc.nextInt();
• To print numbers:
System.out.println(x);
• “Do Not”s
– Do not read from a disk file/write to disk file
– Do not write anything to screen except the result
• Ex: Human centric messages (“the result is”, “please enter..”)
• Automated grading via script will be used for checking
correctness of your output
• Submission through Blackboard
– Submit as a zip file with name
“0_LastName_FirstName.zip” and include:
• Java source code in a file cmsc401.java
• The file should have your name in a comment in
the first line