Description
• Write a program that prints the multiplication 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 multiply and print
Example: (colors are just for visualization):
8/23/18 13
Input:
3
5 13 2 5 1 3
6 5 3 6 7 4 2
9 7 12 2 14 5 7 9 6 3
Output:
65
21
14
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
8/23/18 14
Trial Assignment
• Due: next Thursday, Aug 30th, 11:59pm
• Submission through Blackboard
– Submit as a zip file with name “0_LastName_FirstName.zip” and
include:
• Java source code in a single file cmsc401.java (all lower case letters!)
• The file should have your name in a comment in the first line
• Remember: in Java, class name should match the file name, and is case
sensitive
• Please do NOT create your own packages
• Do NOT place the file into a folder – just zip the file
• Use standard I/O to read input (System.in, System.out) and output
• Make sure the program compiles
8/23/18 15