Question

Write a java code that allows the user to input any name (up to 10 only)...

Write a java code that allows the user to input any name (up to 10 only) and then sorts and alphabetizes them in an array without using predefined methods (.compareTo(), or any sorter functions) and then print out the results.

Homework Answers

Answer #1

code

import java.util.*;
public class Main
{
   public static void main(String[] args)
   {Scanner s=new Scanner(System.in);
  //input
      String[] name = new String[10];
      for(int i=0;i<10;i++)
      name[i]=s.nextLine();
      
      int size = name.length;
      for(int i = 0; i < size - 1; i++)
      {
         for(int j = i + 1; j < name.length; j++)
         {
             //sort the words
            if(name[i].charAt(0)>name[j].charAt(0))
            {
               String temp = name[i];
               name[i] = name[j];
               name[j] = temp;
            }
         }
      }
      //result
      System.out.println("After sorting : ");
      for(int i=0;i<size;i++)
      System.out.print(name[i]+",");
   }
}

//screenshot of the code

output:

--------------------------------------------

Know the answer?
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
Similar Questions
IN JAVA: Write code (using ArrayLists) to read a line of input from the user and...
IN JAVA: Write code (using ArrayLists) to read a line of input from the user and print the words of that line in sorted order, without removing duplicates. For example, the program output might look like the following: Type a message to sort: to be or not to be that is the question Your message sorted: be be is not or question that the to to
USING JAVA: I was asked to write a function that obtains a name from the user...
USING JAVA: I was asked to write a function that obtains a name from the user and returns it in reverse order (So if the user inputs "MIKE" the function returns "EKIM"). You can't use string variables it can only be done using a Char Array. Additionally, you can use a temporary Char Array but you are supposed to return the reverse order in the same char array that the user input, this is for hypothetical cost purposes -we are...
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two different classes in the program being made as objects in the main (Bunny class and Dog Class). ask the user "what kind of animal would you like to sort?" user chooses the type of animal (bunny or dog), then you ask the user how big would you like the array of animals to be (maximum array size = 20)? and then you ask what...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Write code in java Implement a method to build an AVL tree out of a sorted...
Write code in java Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a program that will prompt a user to input coordinates for all the corners and...
Write a program that will prompt a user to input coordinates for all the corners and AutoCAD will draw a quadrilateral automatically with your program. The program should draw the quadrilateral on AutoCAD screen and print out all the coordinates with x and y coordinates only. Use GETPOINT, CAR, and CADR for writing the following program. Make sure this program will work with any coordinates that a user may input. None of the numerical coordinates should be in the programming...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT