Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Look at the following array definition int 1 values 2, 5, 6, 4,7; What is the

ID: 3701373 • Letter: 1

Question

1. Look at the following array definition int 1 values 2, 5, 6, 4,7; What is the output of the following lines? System.out.println(values[2]) x-values 1] 2 values[4 System.out.println(x) x-++values 3]: System.out.println(x); 2. setDescription(String str) and setUnit(int num) are the mutor methods of class Inventoryltem void setDescription (String str) void setDescription (String str) Description str; The following statement creates an Inventoryltem array: Inventoryltem ] items new Inventoryltem[5]; Is it correct or not to execute the following statements? If it is not correct, write the correct one a. items[0]. setDescription("Hammer"); b items.setUnit(10); 3. Use the following int array int [] numbers 78, 29, 12, 56, 98, 44, 75,99, 17, 25) Write the code to store these values of intArray to a file name numbers.txt with the following format. Numbers 0 78 Numbers 1-29 Numbers 2 12 Numbers 3 56 Numbers 4 98 Numbers 5 44 Numbers 6 75 Numbers 7 99 Numbers 8 17 Numbers 9 25 Remember to close the file

Explanation / Answer

Ans:1

6

19

5

===============================================================

Ans:2

I do not know thw answer..

===============================================================

Ans:3

Program:

===============================================================

import java.io.FileWriter;
public class Write_to_file
{
public static void main(String args[])

{

int [] numbers = {78, 29, 12, 56, 98, 44, 75, 99, 17, 25};

try
{

FileWriter fw = new FileWriter("numbers.txt");

for(int i =0; i<numbers.length;i++)

{

fw.write(" Number "+i+" = "+numbers[i]);

}

fw.close();

}catch(Exception e)

{
System.out.println(e);
}

}

}


==============================================================

numbers.txt file:

Number 0 = 78
Number 1 = 29
Number 2 = 12
Number 3 = 56
Number 4 = 98
Number 5 = 44
Number 6 = 75
Number 7 = 99
Number 8 = 17
Number 9 = 25

================================================================

Kindly Check and Verify Thanks..!!!

================================================================