0% found this document useful (0 votes)
9 views4 pages

FJP Expt 5 Code

The document discusses two Java programs - one to sort a list of integers and another to sort a list of names. It includes the code for both programs and sample outputs. The objective is to learn arrays and strings in Java.

Uploaded by

Sushant Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

FJP Expt 5 Code

The document discusses two Java programs - one to sort a list of integers and another to sort a list of names. It includes the code for both programs and sample outputs. The objective is to learn arrays and strings in Java.

Uploaded by

Sushant Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

J.S.P.M.

’S
Jayawantrao Sawant College of Engineering, Hadapsar, Pune-28
Department of Electronics and Telecommunication Engineering
Academic year (2022-23) Semester-I
Subject: Fundamentals of JAVA Programming Lab

/* Subject: Fundamentals of JAVA Programming */


/*Lab Experiment: 5 */
/* Division:TE(B) */
/*Name of Student: Pratik Roman */
/*Roll No: 3255 */
/*Title: Write Programs in Java to sort i) List of integers ii) List of names.
The objective of this assignment is to learn Arrays and Strings in
Java.*/

/* i)Program to Sort List of integers in Java */


import java.io.*;
import java.util.Scanner;
public class SortInt
{
public static void main(String args[])
{
System.out.println("Enter your name:");
System.out.println("Enter your roll no:");
int n,i,j,temp;
Scanner input= new Scanner(System.in);
System.out.println("Enter number of elements:");
n= input.nextInt();
int array[]= new int[n];
System.out.println("Enter integer numbers:");
for(i=0; i<n; i++)
array[i]=input.nextInt();
for(i=0; i<(n-1);i++)
{
for(j=0;j<n-i-1; j++)
{
if(array[j]> array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
J.S.P.M.’S
Jayawantrao Sawant College of Engineering, Hadapsar, Pune-28
Department of Electronics and Telecommunication Engineering
Academic year (2022-23) Semester-I
Subject: Fundamentals of JAVA Programming Lab

}
System.out.println("Sorted list....");
for(i=0; i<n; i++)
System.out.println(" "+array[i]);
}
}

/* Sample Output:
Enter number of elements:
4
Enter integer numbers
3
1
5
7
Sorted list....
1
3
5
7
*/

/* ii) Program to Sort List of names in Java */


public class sorting
J.S.P.M.’S
Jayawantrao Sawant College of Engineering, Hadapsar, Pune-28
Department of Electronics and Telecommunication Engineering
Academic year (2022-23) Semester-I
Subject: Fundamentals of JAVA Programming Lab

{
public static void main(String[] args)
{
System.out.println("Enter your name:");
System.out.println("Enter your roll no:");
// storing input in variable
int n = 4;
// create string array called names
String names[]= { "Rahul", "Ajay", "Gourav", "Vinith" };
String temp;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{

// to compare one string with other strings


if (names[i].compareTo(names[j]) > 0)
{
// swapping
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
// print output array
System.out.println("The names in alphabetical order are: ");
for (int i = 0; i < n; i++)
{
System.out.println(names[i]);
}
}
}

/* Sample Output:
J.S.P.M.’S
Jayawantrao Sawant College of Engineering, Hadapsar, Pune-28
Department of Electronics and Telecommunication Engineering
Academic year (2022-23) Semester-I
Subject: Fundamentals of JAVA Programming Lab

The names in alphabetical order are:


Ajay
Gaurav
Rahul
Vinith
*/

You might also like