Answer to Question #319831 in Java | JSP | JSF for hussain

Question #319831

Task 2: Internet traffic As a digital business analysist, you have been asked by your line manager to supply the last seven months traffic figures to your company’s website. At the moment, the traffic numbers are not in ascending order. Write the pseudocode to solve the initial problem and then write a Java algorithmic program to sort the array of given traffic figures. The traffic numbers to sort correctly are: 2, -17, 8, 26, 1, 0, 84 Hint: Bubble sort 


1
Expert's answer
2022-03-28T14:28:52-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int[] arr = new int[7];
        boolean isSorted = true;
        int buf;

        for (int i = 0; i < arr.length; i++) {
            System.out.print("Month " + (i + 1) + ": ");
            arr[i] = in.nextInt();
        }

        for (int i = 0; i < arr.length; i++){
            for (int j = 0; j < arr.length - 1; j++) {
                if (arr[i] < arr[j]) {
                    buf = arr[i];
                    arr[i] = arr[j];
                    arr[j] = buf;
                }
            }
        }

        for (int i : arr) {
            System.out.print(i + " ");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS