-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCar.java
More file actions
46 lines (45 loc) · 1.07 KB
/
Car.java
File metadata and controls
46 lines (45 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
class Car
{
public String Car_name;
public int Car_No;
public int price;
public Car(String Car_name,int Car_No,int price)
{
this.Car_name=Car_name;
this.Car_No=Car_No;
this.price=price;
}
public static void Display(Car[] obj)
{
for (int i = 0; i < obj.length; i++)
{
for (int j = i+1; j < obj.length; j++)
{
if(obj[i].price < obj[j].price)
{
Car t = obj[i];
obj[i]= obj[j];
obj[j]= t;
}
}
}
for (int i=0;i<obj.length;i++)
{
System.out.println(obj[i].Car_name +" "+ obj[i].Car_No);
}
}
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("enter size");
int size = s.nextInt();
Car obj[] = new Car[size];
for(int i=0;i<obj.length;i++)
{
System.out.println("enter the Details");
obj[i]=new Car(s.next(),s.nextInt(),s.nextInt());
}
Car.Display(obj);
}
}