Lab Cycle 2: Program To Sort Strings
Lab Cycle 2: Program To Sort Strings
Lab Cycle 2: Program To Sort Strings
Lab Cycle 2
import java.util.Scanner;
import java.util.Arrays;
public class sort {
public static void main(String[] args) { int
i,j;
Scanner sc = new Scanner(System.in);
System.out.println("Name: Athul Ajay");
System.out.println("Reg No: SJC22MCA-017");
System.out.println("Date: 28/03/2023");
System.out.println("Course code: 20MCA132");
System.out.println("Enter the number of
words"); int num=sc.nextInt(); String word[]=new
String[num]; sc.nextLine(); for( i=0;i<num;i++){
System.out.println("\nEnter a Word\n");
word[i]=sc.nextLine();
}
for( i=0;i<num-1;i++){
for( j=i+1;j<num;j++){
if(word[i].compareTo(word[j])>0)
{ String temp = word[i];
word[i]=word[j]; word[j]=temp;
}
}
}
System.out.println("Sorted Strings using CompareTo function
="+Arrays.toString(word));
System.out.println(word);
}}
import java.util.Scanner;
}
}
import java.util.Scanner;
public class String_man{ public static
void main(String[] args) {
System.out.println("Name: Athul Ajay");
System.out.println("Reg No: SJC22MCA-017");
System.out.println("Date: 28/03/2023");
System.out.println("Course code: 20MCA132");
System.out.println();
System.out.println("Enter The String");
eName; double
eNo, String
eName, double
eSalary) {
this.eNo = eNo; this.eName = eName;
this.eSalary =
eSalary;
}
System.out.println("Employee found:
eNo=" + employee.eNo + ",
eName="
+ employee.eName + ", eSalary=" + employee.eSalary); found =
true; break;
} } if
(!found) {
System.out.println("Employee not found.");
}
scanner.close();
}
}