Question

In: Computer Science

WITH using methods create an array with numbers

IN JAVA  

Prompt 3:
WITH using methods create an array with numbers
int [] number = { 35, 68, 80, 34, 45, 79, 80};
Display the numbers in the array using for loop
Display the sum
Find biggest element in the array
Display the numers in the array with index numbers
Display the numers using for loop in ascending order (sort)

Solutions

Expert Solution

typed code:

public class Main
{
   public static void main(String[] args) {
       int[] number = {35,68,80,34,45,79,80};
       System.out.println("#####DIAPLAY OF ARRAY ELEMENTS#####");
       for(int i = 0;i        System.out.print(number[i]+" "); // displaying each element in initialized array
       }
       System.out.println();
       System.out.println("#####SUM DISPLAY:######");
       int sum = 0;
       for(int i = 0;i        sum = sum + number[i];
       }
       System.out.println(sum); // printing sum
       int x = number[0];
       for(int i = 1;i        if(x < number[i]) {
       x = number[i]; // storing 1 variable and swaping the variables to x
       } // so that biggest element will get
       }
       System.out.println("biggest is " + x); //printing biggest element
       System.out.println("#####index with elements######");
      
       for(int i = 0;i        System.out.println(number[i]+" "+i+"index"); // priniting index with i elements
       }
       int xx = 0;
       for(int i = 0;i        for(int j = i+1;j        if(number[i]>=number[j]){
       xx = number[i]; // numbers are swaping if it is > j index
       number[i] = number[j];
       number[j] = xx;
       }
       }
         
       }
       System.out.println("###ASCENDING ORDER OF ARRAYA###");
       for(int i = 0;i        System.out.print(number[i]+" ");
       }
      
   }
  
}
SCREEN SHOT :


Related Solutions

Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers and then outputs the largest number.
Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers.
Programing in Scala language: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers. Write separate methods to get an element (given parametersrow and col), set an element (given parametersrow, col, and value), and output the matrix to the console formatted properly in rows and columns. Next, provide an immutable method to perform array addition given two same-sized array.
In C Programing Create a stack using an array. Define the index variable of the array...
In C Programing Create a stack using an array. Define the index variable of the array name to be stacktop. Initially set stacktop to -1. Next create two functions push and pop. Both take as input 3 items: a pointer to the stack in memory, stacktop, and maxstack. Make sure to inc stacktop by one and also remember that stacktop[0] is the bottom of the stack and by stack rule cannot be accessed until all the other items are popped....
IN MATLAB!! Q6. Create a 1D array of numbers and implement ‘Merge Sort’ in MATLAB to...
IN MATLAB!! Q6. Create a 1D array of numbers and implement ‘Merge Sort’ in MATLAB to sort it in ascending order
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then calculates the arithmetic mean (otherwise known as the average), the median (that is, the number that splits the set of value in half with half being above and half being below the number), and the standard deviation (that is, the average of distance each number is from the mean then squared). Further information about these calculations can be found here: average: http://en.wikipedia.org/wiki/Average (add up...
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending...
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. I need this in java language.
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. (Write a C# program)
java program that coverts base13 to decimal. without using array and methods.
java program that coverts base13 to decimal. without using array and methods.
How to inhabit the int array num with random numbers using a function that you then...
How to inhabit the int array num with random numbers using a function that you then invoke from the main method. I already created a function that generates an array of 5 random integers. /* int i;   int arrayName[5];     for(i= 0;i < 6; i++ ){            //type arrayName[arraysize];            arrayName[i] = rand()% 200;       printf("array[%d] = %d\n",i,arrayName[i]); */ // use rand() % some_number to generate a random number int num[5]; int main(int argc, char **argv) { // hint // function invocation goes here...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT