Computer Science, asked by sultanaabeda64, 11 months ago

write a program input city and temperature and sort according to city using bubble sort method using buffered Reader​

Answers

Answered by viny10
5

Explanation:

import java.io.*;

class CitySort

{

public static void main (String args[]) throws IOException

{

int n,len,len1,c,i,j,k=0,m=0;

String str[]=new String[5] ;

String s1;

String s2,temp;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

for (i=0;i<5;i++)

{

System.out.println(“Enter the string “+i+” of the Array :=> “);

str[i]= br.readLine();

}

System.out.println(“\nSorted Strings are :-”);

for(i=0;i<5;i++)

{

for(j=i+1;j<5;j++)

{

if(str[j].compareTo(str[i])<0)

{

temp=str[i];

str[i]=str[j];

str[j]=temp;

}

}

System.out.println(str[i]);

}

}

}

Answered by suraj62111
4

PROGRAM......

import java.util.Scanner; class BubbleSortExample { public static void main(String []args) { int num, i, j, temp; Scanner input = new Scanner(System.in); System.out.println("Enter the number of integers to sort:"); num = input.nextInt(); int array[] = new int[num]; System.out.println("Enter " + num + " integers: "); for (i = 0; i < num; i++) array[i] = input.nextInt(); for (i = 0; i < ( num - 1 ); i++) { for (j = 0; j < num - i - 1; j++) { if (array[j] > array[j+1]) { temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } System.out.println("Sorted list of integers:"); for (i = 0; i < num; i++) System.out.println(array[i]); } }

import java.util.Scanner; class BubbleSortExample { public static void main(String []args) { int num, i, j, temp; Scanner input = new Scanner(System.in); System.out.println("Enter the number of integers to sort:"); num = input.nextInt(); int array[] = new int[num]; System.out.println("Enter " + num + " integers: "); for (i = 0; i < num; i++) array[i] = input.nextInt(); for (i = 0; i < ( num - 1 ); i++) { for (j = 0; j < num - i - 1; j++) { if (array[j] > array[j+1]) { temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } System.out.println("Sorted list of integers:"); for (i = 0; i < num; i++) System.out.println(array[i]); } }Output:

import java.util.Scanner; class BubbleSortExample { public static void main(String []args) { int num, i, j, temp; Scanner input = new Scanner(System.in); System.out.println("Enter the number of integers to sort:"); num = input.nextInt(); int array[] = new int[num]; System.out.println("Enter " + num + " integers: "); for (i = 0; i < num; i++) array[i] = input.nextInt(); for (i = 0; i < ( num - 1 ); i++) { for (j = 0; j < num - i - 1; j++) { if (array[j] > array[j+1]) { temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } System.out.println("Sorted list of integers:"); for (i = 0; i < num; i++) System.out.println(array[i]); } }Output:Enter the number of integers to sort: 6 Enter 6 integers: 12 6 78 9 45 08 Sorted list of integers: 6 8 9 12 45 78

IT WILL DEFINETLY HELP U......

Similar questions