Anda di halaman 1dari 2

Improve the understandability of the below given code:

import java.util.*; class problem3 { int[] numArray = new int[10]; public static void incrementElements (int[] integerArray) { int arraylen = integerArray.length; for (int i = 0; i < arraylen; i ++) { System.out.println(integerArray[i]); } for (int i = 0; i < arraylen; i ++) { integerArray[i] = integerArray[i] + 10; } for (int i=0; i < arraylen; i ++) { System.out.println(integerArray[i]); } } Answer: This code is based on the component classes of java.util.*-The Component class i s the abstract superclass of the nonmenu-related Abstract Window Toolkit(AWT) comp onents. java.util package contains a wide array of functionality, it also contains one o f java's most powerful subsystems. the code defines that when any element of the integer array is occured then it i s printed first and then it is incremented by 10 anf finally the resultant array is printe d.Here an array named numarray is assigned containing 10 elements, which defines the size of the array. we obtain the following explainations from the above given code: This code is based on the component classes of java.util.* Here an array named numarray is assigned containing 10 elements, which defines t he size of the array. public static void...... from this line main() method begins,All java application begin execution by call ing main() next the arraylength is calculated using integerArray.length. after that we have used a for loop from 0 to the obtained length of the array.

System.out.println(..... This line outputs the string"integerArray[i]".System is a predefined class that provide acess to the system,and out is the output stream that is connected to the consol e. next the present integer value is incremented, by a value of 10 and then the control passes to the next element in the array. Now we have the display the resulted array using the final code: for (int i=0; i < arraylen; i ++) { System.out.println(integerArray[i]); }

Anda mungkin juga menyukai