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
6 Replies
JavaBot
JavaBot•3w ago
⌛ This post has been reserved for your question.
Hey @not.lethal! Please use /close or the Close Post button 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot•3w ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
JavaBot
JavaBot•3w ago
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
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
dan1st
dan1st•3w ago
What is the problem with it?
Madjosz
Madjosz•3w ago
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.
JavaBot
JavaBot•3w ago
💤 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.

Did you find this page helpful?