Answered step by step
Verified Expert Solution
Question
1 Approved Answer
give me these two diagram especially flowcharts? import java.util.Random; import java.util.Scanner; public class SecretPhrase { public static void main(String[] args){ Random rand = new Random();
give me these two diagram especially flowcharts?
import java.util.Random; import java.util.Scanner; public class SecretPhrase { public static void main(String[] args){ Random rand = new Random(); Scanner input = new Scanner(System.in); String[] phrases = new String[10]; phrases[0] = "No man is an island"; phrases[1] = "All that glitters is not gold"; phrases[2] = "An eye for an eye makes the whole world blind"; phrases[3] = "All we have to decide is what to do with the time that is given to us"; phrases[4] = "You have brains in your head You have feet in your shoes You can steer yourself any direction you choose"; phrases[5] = "You only live once, but if you do it right, once is enough"; phrases[6] = "I can't go back to yesterday because I was a different person then"; phrases[7] = "It does not do to dwell on dreams and forget to live"; phrases[8] = "Do not wait to strike until the iron is hot make it hot by striking"; phrases[9] = "You can't control the direction of the wind, but you can adjust your sails"; String phrase = phrases[rand.nextInt(10)]; char[] letters = phrase.toCharArray(); int length = letters.length; int guesses = 0; char[] guessed = new char[length]; System.out.print("Enter a letter: "); char guess = input.next().charAt(0); while (guesses < length){ guessed[guesses] = guess; boolean correct = false; for (int i = 0; i < length; i++){ if (letters[i] == guess) { correct = true; break; } } if (correct){ System.out.print("Correct! "); for (int i = 0; i < length; i++){ boolean print = false; for (int j = 0; j <= guesses; j++){ if (letters[i] == guessed[j]){ print = true; break; } } if (print){ System.out.print(letters[i]); } else{ System.out.print("*"); } } System.out.println(); } else{ System.out.println("Nope."); } guesses++; System.out.print("Enter a letter: "); guess = input.next().charAt(0); } System.out.println("Congratulations, you've guessed the phrase!"); input.close(); } }
public static int[] getArray(){ Scanner scan = new Scanner(System.in); System.out.print("Enter the array size:"); int size = scan.nextInt(); int array[] = new int[size]; System.out.println("Enter the array elements:"); } public static void printArray(int[] integerArray){ int length = integerArray.length; for(int i = 0; i < length; i++){ System.out.printf("%-5d", integerArray[i]); if((i+1) % 5 == 0) System.out.println(); } } public static int findMax(int[] arr){ int max = arr[0]; for(int i = 1; i < arr.length; i++){ if(arr[i] > max){ max = arr[i]; } } return max; } public class MinValue{ public static void main(String[] args){ int[] myArray = {5, 10, 0, -5}; int min = findMin(myArray); System.out.println("The minimum is " + min); } public static int findMin(int[] array){ int min = array[0]; for (int i = 0; i < array.length; i++) { if (array[i] < min) { min = array[i]; } } return min; } } public static int findMaxIndex(int[] array){ int max = array[0]; int maxIndex = 0; for (int i = 1; i < array.length; i++){ if (array[i] > max) { max = array[i]; maxIndex = i; } } return maxIndex; } public class MinIndex{ public static int findMinIndex(int[] array){ int index = -1; if(array.length != 0){ int min = array[0]; for (int i = 0; i < array.length; i++) { if (min > array[i]) { min = array[i]; index = i; } } } return index; } public static void main(String[] args){ int [] array = {2,3,4,1,0,5}; int [] emptyArray = {}; System.out.println(findMinIndex(array)); System.out.println(findMinIndex(emptyArray)); } } public class Question7{ public static void main(String[] args){ int[] a = {1, 2, 3, 4, 5}; System.out.println(isSortedAscend(a)); } public static boolean isSortedAscend(int[] a){ boolean flag = true; for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { flag = false; break; } } return flag; } } public class isSortedDescend{ //main method public static void main(String[] args) { //declare array int[] myArray= {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //call method isSortedDescend(myArray); } //method public static void isSortedDescend(int[] myArray) { //declare variable int counter=0; //compare + for(int i=0; i=myArray[i+1]) counter++; //check if array is sorted in descending order if(counter==myArray.length-1) System.out.println("Array is sorted in descending order"); else System.out.println("Array is not sorted in descending order"); } } public class SwapNeighbor{ public static void main(String[] args) { int[] data = {12, 9, 15, 7, 3}; swapNeighbor(data); } public static void swapNeighbor(int[] A) { for(int i = 0; i < A.length - 1; i++) { if(A[i] > A[i + 1]) { int temp = A[i]; A[i] = A[i + 1]; A[i + 1] = temp; } } } } package merge; public class MergeArrays{ public static void main(String[] args) { int [] array1 = {3, 7,8,10,11}; int [] array2 = {2, 5, 6, 9,12,15}; int [] mergedArray = merge(array1,array2); for(int i=0; i
Could you give me these two diagram especially flowcharts?
Thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a basic flowchart illustrating the logic of the SecretPhrase Java program Start Initialize phr...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started