I want to read a list of elements and pass a maximum of 99 elements to a function for some logical operations.
I have tried this with an array as an example and this code was successful in achieving my purpose.
I just want someone to review it and help optimize it.
/**
*/
package com.review.code.java;
/**
* i> Read a List Input,
* ii> Call a Function with maximum of 99 elements in one iteration Eg:(0..98; 99..198; 199..297; .....)
*
*
*/
public class OptimizeReadingList {
public static int list_size=107;//252,543,... etc. - Input List Size
public static int a[] = new int[list_size];
public static void main(String[] args) {
int read_max_size = 99;
int input_list_size = list_size;
// Add Elements to the Array
for(int j =0;j<input_list_size;j++){
a[j]=j+1;
}
// Print all the Elements in the List
for(int j =0;j<input_list_size;j++){
System.out.print(a[j]+",");
}
System.out.println("\n Print only a max of 99 elements in one iteration using the printElements method");
// Should Call a function printElements with start_index and end_index
for(int i = 0,ele = (read_max_size-1); i<input_list_size ; ){
printElements(i,ele);
// Increment Operations for the next elements(maybe another 99 or less than 99)
i=(ele+1);
if((ele+read_max_size > input_list_size)){
ele=input_list_size;
}else{
ele=ele+ele;
}
}
}
// Consider that this method can read only a maximum of 99 elements in range.
private static void printElements(int i, int ele) {
for(int j = i;j<ele;j++){
System.out.print(a[j]+",");
}
System.out.println("\n");
}
}
code samples
, not foreverything
thatyou
wantto
beemphasized
(there is Strong and Emphasis for that purpose). \$\endgroup\$