Translate the following pseudocode for randomly permuting the characters in a string into a Java
Read a word.
Repeat word, length () times
Pick a random position i in the word, but not the last position.
Pick a random position j > i in the word.
Swap the letters at positions j and i.
Print the word.
To swap the letters, construct substrings as follows:
Then replace the string with
first + word.charAt(j) + middle + word.charAt(i) + last
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Problem Solving with C++ (10th Edition)
Management Information Systems: Managing The Digital Firm (16th Edition)
- Language: Java Write a program that reads a sentence from the keyboard. Depending on the last character of the sentence, print the message identifying the sentence as declarative (ends with a period), interrogative (ends with a question mark), exclamatory (end with an exclamation point), or other. Hint: you can use charAt() method from the String class to extract the last character of the input line. The character of a String str is at str.length()-1 position. For taking a sentence as input use the nextLine() method from the Scanner class. You have to use if/else if selection. Sample input and output: Sample 1 Input: How are you? Output: Interrogative Sample 2 Input: I am good. Output: Declarative Sample 3 Input: That is amazing! Output: Exclamatory Sample 4 Input: Although, Output: Other Answer:arrow_forwardif strings are immutable, like in Java, we can assume that they have a static length True Falsearrow_forwardUsing Javascript and HTML: An interesting application of computers is drawing graphs and bar charts (sometimes called histograms). Write a script that reads five numbers between 1 and 30. For each number read, output HTML5 text that displays a line containing the same number of adjacent asterisks. For example, if your program reads the number 5, it should out HTML5 test that displays *****.arrow_forward
- Asaparrow_forward: Write a java program that count the number of letters in a String and find the first occurrence of S, U, I, T in the String and return indices of S, U, I, T. Join the three initialized Strings string1, string2, and string3. Count the number of white spaces in the complete string. Use toUpperCase() and replaceAll("\\s", "") methods to convert string into Upper Case and remove all white Spaces from the string. Count the number of letters in the string. Find the first occurrence of S, U, I, T in the String and return indices of S, U, I, T. Strings are given below: String string1 = "Globalization and Information Technology continue to process at a dramatic pace" String string2 = "To answer the demand of a changing society Pakistan higher education system needs to shift its focus from individuals who simply absorb knowledge to those who are able to creatively utilize knowledge to excel in unfamiliar situations"; String string3 = "These creative individuals should be able to track…arrow_forwardWrite a code that generates a random lowercase letter. In java programming. Note: Not a string of letters just one letter is generated every time the program is run. meaning the output should not be something like this: a c t c -that's a random string, it should only be one random letter generated randomly.arrow_forward
- Java A string is given with words (from 3 to 30), separated by a "," and after the last word a dot ("."). Print all different words and the number of their repetitions. Example: "Cat,dog,cook,knife,dog, man,soap,dog,soap." ----------------- Cat 1 dog 3 cook 1 knife 1 man 1 soap 2arrow_forward1) We will find out the character that gets repeated maximum times in a string. For example, in string "apple", 'p' repeats maximum times. Write a program in Java to find out the maximum repeated character in a string. solve in javaarrow_forwardDetermine whether a string is a palindrome A palindrome is a string of characters that reads the same from right to left as it does from left to right, regardless of punctuation and spaces. Some famous English palindromes include the following “Madam, I’m Adam”, and “Never odd or even”. Of course, a simpler example would be the world “radar”.The specifications for this assignment are: Write and test a non-recursive solution in Java that determines whether a string is a palindrome •Your program should consist of at least two methods: (1) the main method (2) the method which performs the task of determining whether the specified string is a palindrome. You should name this method isPalindrome. You should name the class that contains your “main” method and the isPalindrome method FindPalindrome. •You must use a Stack and a Queue in your solution:Make sure to Write your own Stack and Queue based on the Vector in the Java API and use those in your solution. You should name those classes…arrow_forward
- No loopsarrow_forwardUse for loop in Java language Write the method stringSplosion().* * The method takes one parameter, a non-empty String str (such as "Code") and* returns a String in the form "CCoCodCode". Notice that this includes the* first character of the original String, followed by the first two characters,* and so on until the whole String is used.* * Examples: stringSplosion("Code") returns "CCoCodCode" stringSplosion("abc")* returns "aababc" stringSplosion("x") returns "x"* * @param str the input String to process.* @return a new String as described above.arrow_forwardIn JAVA language, input a string that contains only digits. Swap the first and the last digit of the string and print the string in the output.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education