arrays Java import java util Scannern public class arraysj public static void na
ID: 3825392 • Letter: A
Question
arrays Java import java util Scannern public class arraysj public static void nain(stringt argo) int at j new intt 1011 declares array a with 10 cells int size 7i this is number of elementa we'll havo in the array a. Input Array (a, size) syntem.out.println( the sorted array isi int sorted m new int[10]: sorted Bubblesort (a,size): output Array (sorted,size): end of main program public static void InputArray (int xt], int nize) Scanner input new Scanner (System.in) int i; system out.println "Enter size "data: iExplanation / Answer
package com.server;
class Student1 implements Comparable<Student1>{
int rollno;
String name;
int age;
Student1(int rollno,String name,int age){
this.rollno=rollno;
this.name=name;
this.age=age;
}
public int compareTo(Student1 st){
if(age==st.age)
return 0;
else if(age>st.age)
return 1;
else
return -1;
}
}
package com.server;
import java.util.*;
import java.io.*;
public class MyClient{
public static void main(String args[]){
ArrayList<Student1> al=new ArrayList<Student1>();
al.add(new Student1(101,"Vijay",23));
al.add(new Student1(106,"Ajay",27));
al.add(new Student1(105,"Jai",21));
Collections.sort(al);
for(Student1 st:al){
System.out.println(st.rollno+" "+st.name+" "+st.age);
}
}
}
out put:
105 Jai 21
101 Vijay 23
106 Ajay 27
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.