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 method evenOdd() that sorts an array into even numbers on one side and the...
Create a method evenOdd() that sorts an array into even numbers on one side and the odd numbers on the other side public class ourArray { int[] Ar; int size; public int getSize() {    return size; } public ourArray() {    Ar = new int[100];    size = 0; } public void add(int e) {    Ar[size]= e;    size++; } public int remove() {    //save the last item           int save = Ar[size -1];   ...
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)
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 assignment (CISP430 ignore this part) This is only for those who are using Java How many classes do I need? A: Node, Queue, Radix, Driver...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT