File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ class Car
4+ {
5+ public String Car_name ;
6+ public int Car_No ;
7+ public int price ;
8+ public Car (String Car_name ,int Car_No ,int price )
9+ {
10+ this .Car_name =Car_name ;
11+ this .Car_No =Car_No ;
12+ this .price =price ;
13+ }
14+ public static void Display (Car [] obj )
15+ {
16+ for (int i = 0 ; i < obj .length ; i ++)
17+ {
18+ for (int j = i +1 ; j < obj .length ; j ++)
19+ {
20+ if (obj [i ].price < obj [j ].price )
21+ {
22+ Car t = obj [i ];
23+ obj [i ]= obj [j ];
24+ obj [j ]= t ;
25+ }
26+ }
27+ }
28+ for (int i =0 ;i <obj .length ;i ++)
29+ {
30+ System .out .println (obj [i ].Car_name +" " + obj [i ].Car_No );
31+ }
32+ }
33+ public static void main (String [] args )
34+ {
35+ Scanner s =new Scanner (System .in );
36+ System .out .println ("enter size" );
37+ int size = s .nextInt ();
38+ Car obj [] = new Car [size ];
39+ for (int i =0 ;i <obj .length ;i ++)
40+ {
41+ System .out .println ("enter the Details" );
42+ obj [i ]=new Car (s .next (),s .nextInt (),s .nextInt ());
43+ }
44+ Car .Display (obj );
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments