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...

  • import java.util.Scanner; public class Chpt7_Project {    public static void bubbleSort(int[] list)    {    int...

    import java.util.Scanner; public class Chpt7_Project {    public static void bubbleSort(int[] list)    {    int temp;                       for (int i = list.length - 1; i > 0; i--)    {    for (int j = 0; j < i; j++)    {    if (list[j] > list[j + 1])    {    temp = list[j];    list[j] = list[j + 1];    list[j + 1] = temp;    }    }    }   ...

  • 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 }}

  • import java.util.Scanner; public class SieveOfEratosthenes {    public static void main(String args[]) {       Scanner sc...

    import java.util.Scanner; public class SieveOfEratosthenes {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a number");       int num = sc.nextInt();       boolean[] bool = new boolean[num];            for (int i = 0; i< bool.length; i++) {          bool[i] = true;       }       for (int i = 2; i< Math.sqrt(num); i++) {          if(bool[i] == true) {             for(int j = (i*i); j<num; j = j+i) {                bool[j] = false;...

  • Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){...

    Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){ Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String word = kb.next();    String reverse = ""; for (int i=word.length()-1; i>=0; i--) reverse += word.charAt(i); boolean result = reverse.equalsIgnoreCase(word);    if (result) System.out.println("The word " +word+ " is a Palindrome."); else System.out.println("The word " +word+ " is not a Palindrome."); } } Rewrite the program so that the main method is: public static void...

  • 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...

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