Starting from:

$20

CMSC401 Trial Assignment Solved

Trial Assignment

• 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): 

                                Input:                                                              Output:

 3

5    13 2 5 1 3

6    5 3 6 7 4 2

 9 7 12 2 14 5 7 9 6 3

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


More products