Fill This Form To Receive Instant Help
Homework answers / question archive / program using a console application name it "DragonKiller"
program using a console application name it "DragonKiller". The program should ask the user to enter is name and surname.
Use the emptySpace () method to remove space between the name and the surname. Count the number of characters within the newly created string (nameSurname).
The total number of characters (Name and Surname) should be the size of your arrayDragon (type integer). Populate your arrayDragon with a series of random number between 10 and 50.
Display all arrayDragon elements and they are corresponding indexes before executing the insertionSort method.
Allow the user to enter a value from the arrayDragon element to search for.
* Loop through the array until you find the value (Use the binarySearch to locate the value with in your array) and kill that value from the arrayDragon. By replacing the value findDragon with a Zero (0)
* Print out arrayDragon with the killed element.
Answer: import java.util.*; public class DragonKiller { public static int emptySpace(String name){ //replacing the " " with "" to remove empty space name=name.replace(" ",""); //return the length of the name return name.length(); } //method for insertion sort public static int[] insertionSort(int[] array){ int n = array.length; for (int j = 1; j < n; j++) { int key = array[j]; int i = j-1; while ( (i > -1) && ( array [i] > key ) ) { array [i+1] = array [i]; i--; } array[i+1] = key; } return array; } //method to find the element you want to search for public static int findDragon(int[] arr, int key){ int first=0; int last=arr.length-1; int mid = (first + last)/2; while( first <= last ){ if ( arr[mid] < key ){ first = mid + 1; }else if ( arr[mid] == key ){ return mid; }else{ last = mid - 1; } mid = (first + last)/2; } return -1; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name(name and surname):"); String name=sc.nextLine(); //ge the size of the name string int size = emptySpace(name); int arrayDragon[]= new int[size]; int low = 10; int high = 50; Random r = new Random(); for(int i=0;i