Lab Letter: Name: CSE 110 Lab 10: Arrays Pre-lab Questions: Answer thes ns befor
ID: 3808310 • Letter: L
Question
Lab Letter: Name: CSE 110 Lab 10: Arrays Pre-lab Questions: Answer thes ns before your lab session. questio Write Java Code segments to perform following tasks: 1. Create an array of five integers named pumpkin and initialize it to hold the first 5 odd integers. 2. Print the length of pumpkin (ie, the number of elements) to the console. 3. Use a for loop to print the contents of pumpkin, separating each element with a space. 4. Use a for loop to increase the value of each element in pumpkin by 1. 5. Output the first element in pumpkin to the console,Explanation / Answer
Solution:
1.) int [5] pumpkin= {1, 3, 5, 7, 9}; // Array declaration and initialization of first five add numbers.
2.) System.out.println(pumpkin.length); // length of the array will be printed here
3.) for(int i=0; i<pumpkin.length; i++)
{
System.out.println(pumpkin[i]); // Every element will be printed one by one
}
4.)
for(int i=0; i<pumpkin.length; i++) this loop will run length of the matrix number of times
{
pumpkin[i]++; // every element will be incremented by 1
}
5.) System.out.println(pumpkin[0]); // element present at index 0 is first element of the array
6.) System.out.println(pumpkin[pumpkin.length-1]); // Since the array index starts from 0, the last element will be at length-1
to complete your Lab10.java I am providing statements which are required along with comment for better understanding just put them in order in your program.
// Declaration of max and min
int max=0, min=0; // These are index where the index of max and min wll be stored
// Now is the good time to find max index sale index
if(sale[i]> sale[max])
max=i;
// and for min sale index
if(sale[i]<sale[min])
min= i;
// Display the maximum sale
System.out.println("Sales person "+ max+ "has highest sale with "+ sale[max]);
// Display the minimum sale
System.out.println("Sales person "+ min+ "has lowest sale with "+ sale[min]);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.