CMSC 401 Trial Assignment solved

Original price was: $30.00.Current price is: $25.00.



Rate this product

• Write a program that prints the sum of two selected numbers from a
– 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):

5 13 2 5 1 3
6 5 8 6 7 4 2
9 2 12 7 14 5 17 9 6 3

Input/output in Java

• Use Standard I/O to read input and write the result
• For Java, input:, output: System.out
• To read numbers, one option is:
• Use a single Scanner object
Scanner sc = new Scanner(;
• Use nextInt()over and over to read integers
number = sc.nextInt();

• To print numbers:
• “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

Trial Assignment

• Due: next Thursday, Sept 1st
, 11:59pm
• Submission through Blackboard
– Submit as a zip file with name
“” and include:
• Java source code in a file
• The file should have your name in a comment in
the first line