Question

How do you order multiple strings in java alphabetically using ASCII/Unicode orders and string operations? Where...

How do you order multiple strings in java alphabetically using ASCII/Unicode orders and string operations?

Where the input of the strings is done using args[0], args[1], args[2] , etc...

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Arrays;
public class TestCode {
    public static void sort(String s[]){
        int n = s.length, j;
        for (int i=1; i<n; ++i){
            String key = s[i];
            j = i-1;
            while (j>=0 && s[j].compareTo(key)>0){
                s[j+1] = s[j];
                j = j-1;
            }
            s[j+1] = key;
        }
    }

    public static void main(String args[]){
        if(args.length==0){
            System.out.println("Please pass some command line arguments");
        }
        else{
            String s[] = new String[args.length];
            for(int i = 0;i<args.length;i++){
                s[i] = args[i];
            }
            sort(s);
            System.out.println("Order of strings in alphabetical order:");
            for(int i = 0;i<s.length;i++){
                System.out.print(s[i]+" ");
            }
            System.out.println();
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
How do you order multiple strings in java alphabetically using ASCII/Unicode orders and string operations? Where...
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
  • Language is java Create encryption and decryption that changes char by using ASCII by 5. How...

    Language is java Create encryption and decryption that changes char by using ASCII by 5. How to do this using threads? Let’s assume that our password string is “ABCDEFGHI”, once you run the encrypt function on this string you should get - “FGHIJKLMN” (since you are increasing the ASCII value by 5) If we call decrypt on this update string right away, it should give us the original string back - “ABCDEFGHI”

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • How do I do this in Java without using the functional API? I can't use anything...

    How do I do this in Java without using the functional API? I can't use anything special; this is for APCS method header: public List noX(List strings) Functional-1 noX prev | next chance Given a list of strings, return a list where each string has all its "x" removed. Vi nox(["ax", "bb", "cx"]) ["a", "bb", "c"] nox(Тххах", "Xbxbx", "Xxcx"]) ["a", "bb", "c"]

  • Stacks and Java 1. Using Java design and implement a stack on an array. Implement the...

    Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...

  • JAVA QUESTION 2.One use of a Stack is to reverse the order of input. Write a...

    JAVA QUESTION 2.One use of a Stack is to reverse the order of input. Write a complete method that reads a series of Strings from the user. The user enters "end" to stop inputting words. Then, output the Strings in reverse order of how they were entered. Do not output the String “end”. Use a stack to accomplish this task. Invoke only the methods push, pop, peek, and isEmpty on the stack object. Here is an example of how the...

  • What to do This assignment will give you some exposure to how strings are implemented in...

    What to do This assignment will give you some exposure to how strings are implemented in C. Please create one file main.c that contains a driver main() and a function str_len() as follows: int main(void); int str_len(char string[]); Here is what these functions are supposed to do: main() is the driver that calls str_len(). Specifically, main() will take a string from the command line and print out the length of the string, internally using str_len(). str_len() takes one arguments, i.e....

  • You are given a list of strings L = {s1,s2 ...sn}. Each si is a string...

    You are given a list of strings L = {s1,s2 ...sn}. Each si is a string of up to 26 English characters. For example, L consists of the following strings: {s1, 82... Sn}. Each s; is a string of up to 26 English 13. You are given a list of of strings L = characters. For example L consists of the following strings: S1 =hello', S2 = 'world, s3 = 'what', s4 = 'a', 85 = 'nice', s6 = 'day',...

  • using java String Challenge Have the function StringChallenge(str) read str which will contain two strings...

    Have the function wildcard(str) read str which will contain two strings separated by a space.The first string will consist of the following sets of characters: +, *, $ and {N} which is optional.The plus (+) character represents a single alphabetic character, the ($) character represents anumber between 1-9, and asterisk (*) represents a sequence of the same character of length 3unless it is followed by {N} which represents how many characters would appear in thesequence where N will be at...

  • In this assignment, you sort a list of strings using mergesort and the compareToIgnoreCase method of...

    In this assignment, you sort a list of strings using mergesort and the compareToIgnoreCase method of the String class. The strings are provided as arguments to your main method. In case you haven't yet learned to configure command-line arguments to main in your IDE, now is a good time to learn. Your program should sort the array of strings using mergesort, then print the strings one per line, in order from smallest ("a") to largest ("z"). The name of your...

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