Question

Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {...

Draw a flowchart for this program

public class InsertionSort {

    public static void main(String a[]) {

        int[] array = {7, 1, 3, 2, 42, 76, 9};

        insertionSort(array);

    }

    public static int[] insertionSort(int[] input) {

        int temp;

        for (int i = 1; i < input.length; i++) {

            for (int j = i; j > 0; j--) {

                if (input[j] < input[j - 1]) {

                    temp = input[j];

                    input[j] = input[j - 1];

                    input[j - 1] = temp;

                }

            }

            display(input, i);

        }

        return input;

    }

    public static void display(int[] array, int step) {

        System.out.print("Step:" + step+" |");

        for (int num : array) System.out.print(" " + num);

        System.out.println();

    }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

START Sin RT insertion scort(int input(1) Initialise ashey (3 - 7,1,3,2,42,769) int i =) START t Call InsertionSat laway) Dis

If you have any questions comment down and please? upvote thanks

Add a comment
Know the answer?
Add Answer to:
Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • package array; public class Test { static int[] data = (0,1,2,3,4,5,6,7,8); public static void main (String[]...

    package array; public class Test { static int[] data = (0,1,2,3,4,5,6,7,8); public static void main (String[] a) { for ( int i = 0;i<data.length; i++) { if(i %3 == 0) { System.out.print("A"); System.out.print(data[i]); System.out.print(" "); } } I need an explanation of what this code is doing ? is there anything wrong with it }}

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • What is the output of following program: public class Test{ public static void main(String[] args) {...

    What is the output of following program: public class Test{ public static void main(String[] args) { A a = new A(): a method B(): } } class A{ public A(){ System out println("A's constructor is executed"): } public void method(){ System out printin ("methodA is executed"): } public void methodAB(){ System out printin ("As methodAB is executed"): } } class B extends A { private int num = 0: public B (){ super(): System out printin ("B's constructor is executed"):...

  • How to arrange the result neatly? public class LabTest { public static void main(String[] args) {...

    How to arrange the result neatly? public class LabTest { public static void main(String[] args) { String[] state= {"Johor", "Kedah","Kelantan","Melaka","Negeri Sembilan","Pahang","Perak","Perlis","Pulau Pinang","Sabah","Sarawak","Selangor","Terengganu","Wilayah Persekutuan Labuan","Wilayah Persekutuan Kuala Lumpur"}; int [] rainfall= {1133,1312,1699,1220,1450,1596,1350,1189,1347,1987,1999,1125,1789,1980,1374}; int temp; String tempN; for (int i=0;i<rainfall.length;i++){ for (int j=0;j<rainfall.length;j++){ if (rainfall[i]>rainfall[j]){ temp=rainfall[i]; rainfall[i]=rainfall[j]; rainfall[j]=temp;    tempN=state[i]; state[i]=state[j]; state[j]=tempN; } } } for (int i=0;i<rainfall.length;i++){ System.out.print(state[i] + "\t"); } System.out.println(""); for (int i=0;i<rainfall.length;i++){ System.out.print(rainfall[i] + "\t");    } } } Sabah Kelantan Pahang Perak Pulau Pinang Kedah Sarawak Wilayah...

  • What will the following program display? public class checkpoint { public static void main(String urgs[]) {...

    What will the following program display? public class checkpoint { public static void main(String urgs[]) { int n = 1776; doubled = 110.0901; System .out.println(n + “\t” + d); myMethod(n, d); System.out.println(n + “\t” + d); } public static void myMethod(int i, double x) { System.out.printing + “\t” + x); i = 1250; x= 199.99; System.out.println(i + “\t" + x); } } Write the following two methods: i. compute Diameter; This method accepts the radius (r) of a circle, and...

  • import java.util.Arrays; public class lab {    public static void main(String args[])    {    int...

    import java.util.Arrays; public class lab {    public static void main(String args[])    {    int arr[] = {10, 7, 8, 9, 1, 5,6,7};    int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};    int arr3[] = {1, 3, 5, 3, 2, 6, 20};    quicksort(arr,0,arr.length-1);    quicksort(arr2,0,arr2.length-1);    quicksort(arr3,0,arr3.length-1);    System.out.println(Arrays.toString(arr));    System.out.println(Arrays.toString(arr2));    System.out.println(Arrays.toString(arr3));       }    private static int partition(int[] items,int low, int high)    {    int i=0;    int j=0;...

  • What output is produced by the following program? public class MysteryNums public static void main(String[] args)...

    What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT