Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners string array based problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


moni sharma
string array based problem
0 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners


R/sir, firstly thanks to help me so much. but now it can sort string very well but in case of integers as it treats integers here as string, it sorting like this: i/p: 12 14 11 3 sorted value: 11 12 13 3 this is the problem here......

import java.util.*; public class StringArraySelectionSort {

public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
System.out.println("Enter string: ");
String[] array = new String[5];
for(int i=0;i<5;i++){
    array[i]=input.next();
}
selectionSort(array);
for(int i = 0; i < array.length; i++){
System.out.print(array[i]+" ");
 }
}
static String[] selectionSort(String[] array)
{
    for (int i = 1; i < array.length; i++) {
        int s = i-1;
        for (int j = i; j < array.length; j++) {
            if (array[j].compareTo(array[s]) < 0) {
                s = j;
            }
        }
        String temp = array[i-1];
        array[i-1] = array[s];
        array[s] = temp;

    }
    return array;
}

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Array /string based problem....
Array /string based problem....  thanx to help me.but again a problem...("Enter string: "); String[] array = new String[5]; for(int i=0;i<5;i...]+" "); } } static String[] selectionSort(String[] array) { for (int i = 1
string array based problem
string array based problem  R/sir, firstly thanks... string: "); String[] array = new String[5]; for(int i=0;i<5;i++){ array[i...++){ System.out.print(array[i]+" "); } } static String[] selectionSort(String[] array
Advertisements
array and string based problem
array and string based problem  this program is accepting only... main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1
array and string based problem
array and string based problem  this program is accepting only... main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1
array and string based problem
array and string based problem  this program is accepting only... main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new..._srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1
array of string
array of string  Waht is the problem in this code? import java.util.Scanner; public class LastCheck { public static void main(String args[]){ int a; Scanner s= new Scanner(System.in); a=s.nextInt(); String ar[]=new
arry based problem
arry based problem  {modify this proram in such a way so that it can... time.} public class Insertion{ public static void main(String a[]){ int i; int array[]={17,12,3,6,4,19,200}; System.out.println(" Selection Sort\n\n
arry based problem
arry based problem  {modify this proram in such a way so that it can... time.} public class Insertion{ public static void main(String a[]){ int i; int array[]={17,12,3,6,4,19,200}; System.out.println(" Selection Sort\n\n
arry based problem
arry based problem  {modify this proram in such a way so that it can... time.} public class Insertion{ public static void main(String a[]){ int i; int array[]={17,12,3,6,4,19,200}; System.out.println(" Selection Sort\n\n
arry based problem
arry based problem  {modify this proram in such a way so that it can... time.} public class Insertion{ public static void main(String a[]){ int i; int array[]={17,12,3,6,4,19,200}; System.out.println(" Selection Sort\n\n
array to string
array to string  hello how to assign value from array to string. nsstring *abc = [array objectAtindex:1];   you can use this code NSString *abc = [NSString stringWithString:[array objectAtIndex:i]]; where i
string array
string array   Hi hw to print string array element in ascending r... StringArray { public static void main(String[] args) { String arr...); System.out.println("Array Elements in Ascending Order: "); for(int i=0;i<
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
arry based problem
arry based problem  how to put char type & int types variable in same array.and also what the procedure for giving input to those array at run time
arry based problem
arry based problem  how to put char type & int types variable in same array.and also what the procedure for giving input to those array at run time
java program based on array
java program based on array  Create Student class with attributes... StudentDemo which will have main method. Declare array of Student object with size 10. Initialize all 10 elements of this array with new objects. Write logic which
array string
array string  how to sort strings with out using any functions
Problem based on monitors
Problem based on monitors  A file is to be shared among different processes, each of which has a unique number. The file can be accessed simultaneously by several processes, subject to the following constraint: the sum of all
Problem in Array
Problem in Array  Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's. Hoping... if the input string contains equal number of A's and B's. class StringEx { public
array problem
array problem  An integer array a has 19 elements. What is the value of the middle element after the following codes is executed? int i, j,n=19; for (i=0; i for(i=0, j=n-1; i<=j; i++, j--) a[(i+j)/1] -= (a[i]+a[j])/2
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
string array sort
string array sort  Hi. How to sort a string array
String Array - Java Beginners
String Array  From where can I get, all the functions that are needed for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String
php parse string into array
php parse string into array  How can i parse a string into array and convert an array into string
String Array - Java Beginners
this question to you before, now the problem comes if my String Array consisted... for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String
JavaScript split string into array
; Description: The split() method is used to split a string into an array...JavaScript split string into array  How to split the string into array?   <html> <head> <title></title> <script
Array List and string operation
Array List and string operation  hi, I want to search an arraylist element in a a given file. example I have a name called "mac" in my arraylist and I have a txt file which contains mac, how many times "mac" appears in the txt
array split string
array split string  array split string   class StringSplitExample { public static void main(String[] args) { String st = "Hello_World"; String str[] = st.split("_"); for (int i = 0; i <
Advertisements
 

 

 

DMCA.com