My program is not case sensitive it does not display the output my proff wants PLEASE HELP! I don't know how to make it case sensitive
The output should be:
As entered
0:a:apple
1:a:Apple
2:z:Zone
3:a:apple
Bubble Sorted
0:a:apple
1:a:Apple
3:a:apple
2:z:Zone
Selection Sorted
1:a:Apple
0:a:apple
3:a:apple
2:z:Zone
My program does:
As entered
0:a:apple
1:a:Apple
2:z:Zone
3:a:apple
Bubble Sorted
1:a:Apple
2:z:Zone
0:a:apple
3:a:apple
Selection Sorted
1:a:Apple
2:z:Zone
0:a:apple
3:a:apple
Here is my code
package javaapplication9;
import java.util.*;
/**
*
* @author www.homeworkjava.com
*/
public class Main {
static int i = 1;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
String anArray[][];
anArray = new String[100][100];
String data;
System.out.println("Enter data: "); //ask for data
data = in.next();
anArray[0][0] = data;
anArray[0][1] = data.substring(0, 1);
while (!data.equalsIgnoreCase("done"))
{
System.out.println("Enter data: ");
data = in.next();
if (data.equalsIgnoreCase("done")){
break;
}
else {
anArray[i][0]= data;
anArray[i][1]= data.substring(0, 1);
i++;
}
}
System.out.println("As entered");
for (int j = 0; j < i; j++){
String f = String.valueOf(j);
anArray[j][2] = f;
System.out.println(j + ":" + anArray[j][1].toLowerCase()+ ":" + anArray[j][0]); //print result
}
bubblesort(anArray); //call bubble sort
selectionSort(anArray); //call selection sort
}
//bubble sort method
static void bubblesort(String Array[][]){
String datae = null;
String temps;
String tempse;
for(int x=1;x<i;x++)
{
for(int y=0;y<i-x;y++)
{
if(Array[y][1].compareTo(Array[y+1][1])>0)
{
temps=Array[y][1];
Array[y][1]=Array[y+1][1];
Array[y+1][1]=temps;
tempse=Array[y][0];
Array[y][0]=Array[y+1][0];
Array[y+1][0]=tempse;
tempse=Array[y][2];
Array[y][2]=Array[y+1][2];
Array[y+1][2]=tempse;
}
}
}
System.out.println("Bubble Sorted");
for (int z = 0; z < i; z++){
datae = Array[z][0];
Array[z][1]= datae.substring(0, 1).toLowerCase();
System.out.println(Array[z][2] + ":" + Array[z][1]+":" +Array[z][0]);
}
}
//selection sort method
static void selectionSort(String arrays[][])
{
String data = null;
for (int e = 1; e < i; e++) {
// find the index of the ith smallest value
int s = e-1;
for (int j = e; j < i; j++) {
if (arrays[j][0].compareTo(arrays[s][0]) < 0) {
s = j;
}
}
// swap the ith smallest value into entry i-1
String temp = arrays[e-1][0];
arrays[e-1][0] = arrays[s][0];
arrays[s][0] = temp;
temp = arrays[e-1][2];
arrays[e-1][2] = arrays[s][2];
arrays[s][2] = temp;
}
System.out.println("Selection Sorted");
for (int z = 0; z < i; z++){
data = arrays[z][0];
arrays[z][1]= data.substring(0, 1).toLowerCase();
System.out.println(arrays[z][2] + ":" + arrays[z][1]+":" +arrays[z][0]);
}
}
}