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

1. Write a Java program that asks the user of the array size s/he wants to creat

ID: 3537705 • Letter: 1

Question

1.    Write a Java program that asks the user of the array size s/he wants to create. Your program should create the array and use a loop to let the user input the values of the array elements. Your program should find the maximum number among the array elements and display it.

2.    Write a Java program to create an array that holds 10 integer numbers. Use a loop to assign the values to the array elements, should be the first 10 odd numbers, and calculate the sum of all numbers in the array. Then display the sum of the numbers you calculated.

3. (What would be the values of the num array elements after executing the following code, trace and explain.

public class QuestionThree

{

         public static void main(String args [])

         {

               int [] num= {20,50,10,70,40,80,30,90,60};

               int t=0;

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

                               {

                                              for (int j=i+1; j<num.length; j++)

                                              if (num[i]>num[j])

                                              {

                                                             t=num[i];

                                                             num[i]=num[j];

                                                             num[j]=t;

                                              }

                               }

                              

         }

}

Explanation / Answer

import java.util.*;
class test
{
public static void main(String[] args)
{
int size = 0;
Scanner in = new Scanner(System.in);
System.out.println(" Enter size of array you want to create ");
size = in.nextInt();
int max = 0;
int[] array=new int[size];
for(int i=0; i<size; i++)
{
System.out.println(" Enter element "+ (i+1));
array[i]=in.nextInt();
if(array[i] > max) max = array[i];
}
System.out.println(" Max element in array given by "+ max);
}
}




// PART2


import java.util.*;
class test
{
public static void main(String[] args)
{
int[] array=new int[10];
int sum = 0;
for(int i=0; i<10; i++)
{
array[i]=(2*i+1);
sum = sum +array[i];
}
System.out.println(" sum of first 10 odd numbers is "+ sum);
}
}


//PART3.


this is bubble sort...


swap operations will be as follows.


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote