pratice problem
import java.util.Arrays;
import java.util.Scanner;
public class L1P01{
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
String [][]names = new String[5][2];
for(int i =0; i<names.length; i++){ System.out.println("Enter first & last names"); String fullNames = reader.nextLine();
String[] parts = fullNames.split(" ");
names[i][0] = parts[0]; names[i][1] = parts[parts.length-1]; }
for(String[] print : names){ System.out.println(Arrays.toString(print)); } } } Organize Array alphabetically last name , don't use Arrays.sort
for(int i =0; i<names.length; i++){ System.out.println("Enter first & last names"); String fullNames = reader.nextLine();
String[] parts = fullNames.split(" ");
names[i][0] = parts[0]; names[i][1] = parts[parts.length-1]; }
for(String[] print : names){ System.out.println(Arrays.toString(print)); } } } Organize Array alphabetically last name , don't use Arrays.sort
6 Replies
⌛ This post has been reserved for your question.
Hey @not.lethal! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Please format your code to make it more readable. For java, it should look like this:
What is the problem with it?
If you are supposed to sort the array by hand without calling library functions you should pick any sorting algorithm and implement it. Personally I find bubblesort the easiest to implement.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.