|
Muhammad al-Xorezmiy nomidagi Tashkent Axborot Texnologiyalari Universiteti Nukus Filiali
|
tarix | 24.11.2023 | ölçüsü | 1,04 Mb. | | #133567 |
| Algoritm loyihalash . Saralash 1
Muhammad al-Xorezmiy nomidagi Tashkent Axborot Texnologiyalari Universiteti Nukus Filiali
«Kompyuter injiniringi » fakulteti « Dasturiy injiniringi» yo’nalishi 2-kurs 104-21 guruh talabasi Abdibekova Gu’ljanning
«Algoritm loyihalash » fanidan
Laboratoriya ishlari
Qabul qilgan: _____________________________ Sh.Abdig’aniev
Ishlagan: _____________________________ G.Abdibekova
Topshiriq : Talabalar ismlarini alifbo tartibida saralash .
import java.util.Scanner;
public class Lab1
public static void main(String[] args) {
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print("Studentlar soni:");
n = s.nextInt();
String names[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("Ismlarni kiriting:");
for(int i = 0; i < n; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("Natija:");
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[n - 1]);
}
}
Natija
Studentlar soni:5
Ismlarni kiriting:
Akbarali
Shaxzod
Balausa
Guljan
Nigora
Natija:Akbarali,Balausa,Guljan,Nigora,ShaxzodBUILD SUCCESSFUL (total time: 37 seconds)
Dostları ilə paylaş: |
|
|