So, I have an ArryList, and there is a toString method used to print the Strings contained in the ArrayList.
However, whenever I run it, I either get nothing in response or some garbled computer language in return.
What am I missing, or doing wrong?
import java.util.Scanner;
public class main
{
public static void main (String [] args)
{
while (1 == 1)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a name.");
System.out.println();
System.out.print("--> ");
String namae = scan.nextLine();
String checkstop = namae;
checkstop = checkstop.toLowerCase();
String n1 = namae.substring(0, 1);
n1 = n1.toUpperCase();
String n2 = namae.substring(1, (namae.length()));
namae = n1+n2;
for (int i = 0; i < namae.length(); i++)
{
char checker = namae.charAt(i);
String checks = checker + "";
if (checks.equals(" "))
{
char change = namae.charAt(i + 1);
String changes = change + "";
changes = changes.toUpperCase();
String z1 = namae.substring(0, (i));
String z2 = change + (namae.substring((i + 2), (namae.length())));
namae = z1 + z2;
}
}
if (namae.length() < 3)
{
System.out.println("Invalid Input! Too few characters.");
}
else if (checkstop.equals("stop"))
{
break;
}
else
{
send(namae);
}
}
}
public static void send(String namae)
{
InsertionSort s = new InsertionSort(namae);
}
}
and the constructor class:
import java.util.ArrayList;
public class InsertionSort
{
String namae;
public InsertionSort(String namae)
{
this.namae = namae;
}
public void Sort()
{
ArrayList<String> list = new ArrayList<String>();
list.add(namae);
for (int i = 1; i < list.size(); i++)
{
int j = i;
String tmp = list.get(i).substring(0, 1);
for(j = i - 1; j >= 0; j--)
{
if ((tmp.compareTo(list.get(j).substring(0, 1))) > 0)
{
list.set(j ,tmp);
}
if ((tmp.compareTo(list.get(j).substring(0, 1))) == 0)
{
list.set(j ,tmp);
}
if ((tmp.compareTo(list.get(j).substring(0, 1))) < 0)
{
list.set(j ,tmp);
}
}
}
for (int g = 0; g < list.size(); g++)
{
toString(list.get(g));
}
}
public static String toString(String x)
{
System.out.println(x);
return x;
}
}