JAVA PROGRAMMING
LAB FILE
Submitted by : Vasanatarao Ronith Patnaik
Course : Btech CSE
Section : B (Group – 1)
Enrollment no. : A50105220067
Submitted to : Dr. Ashima Gambhir
Program 1: Write a program to print Introduction:-
Source Code :-
class Sample
public static void main(String args[])
[Link]("Good Morning\nMy name is Pinky\nI'm pursuing Btech CSE from
Amity University\nI'am 19 years old\nI love to watch Web series");
OUTPUT :-
Program 2: Write a program to print 3 to 4 features of Java:-
Source Code :-
class ComLineTest
public static void main(String args[])
int count, i = 0;
String s;
count = [Link];
[Link]("No. of arguments are: " + count);
while(i<count)
s = args[i];
i++;
[Link]("Java is "+s);
OUTPUT :-
Program 3: Write a program to find Largest number using Scanner Class-
Source Code :-
import [Link].*;
class Maxnumber
public static void main(String args[])
Scanner x = new Scanner([Link]);
[Link]("Enter the values of a, b and c");
int a = [Link]();
int b = [Link]();
int c = [Link]();
if(a>b && a>c)
[Link]("Largest number is " +a);
else if(b>a && b>c)
[Link]("Largest number is " +b);
else
[Link]("Largest number is " +c);
}
}
OUTPUT :-
Program 4: Write a program to sort a list of 10 numbers and take the input from
the user:-
Source Code :-
import [Link].*;
public class ListSorting
public static void main(String args[])
int a[] = new int[5];
Scanner sc = new Scanner([Link]);
[Link]("Enter the values");
for(int i=0; i<5; i++)
a[i] = [Link]();
for(int i=0; i<5; i++)
for(int j=i+1; j<5; j++)
if(a[i] < a[j])
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
for(int i=0; i<5; i++)
[Link](a[i]+",");
OUTPUT :-
Program 5: Write a program to multiply two matrices:-
Source Code :-
class MatrixMultiply
public static void main(String args[])
int a[][]={{1,1,1},{2,2,2},{3,3,3}};
int b[][]={{1,1,1},{2,2,2},{3,3,3}};
int c[][]=new int[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
c[i][j]=0;
for(int k=0;k<3;k++)
c[i][j]+=a[i][k]*b[k][j];
[Link](c[i][j]+" ");
}//end of j loop
[Link]();//new line
}
}
OUTPUT :-
Program 6: Write a program on Jagged Array:-
Source Code :-
class JaggedArray
public static void main(String args[])
int a[][] = new int[2][];
a[0] = new int[3];
a[1] = new int[2];
int count = 0;
for(int i=0; i < [Link]; i++)
for(int j=0; j < a[i].length; j++)
a[i][j] = count++;
for(int i=0; i < [Link]; i++)
for(int j=0; j < a[i].length; j++)
[Link](a[i][j] + " ");
}
[Link]();
OUTPUT :-
Program 7: Write a program for Alphabetical Ordering of Strings:-
Source Code :-
class StringOrdering
public static void main(String args[])
String name[] = {"Ahmedabad", "Chandigarh", "Rewari", "Mumbai", "Jaipur"};
int count = [Link];
for(int i=0; i<count; i++)
for(int j=i+1; j<count; j++)
if(name[j].compareTo(name[i]) < 0)
String temp = name[i];
name[i] = name[j];
name[j] = temp;
for(int i=0; i<count; i++)
[Link](name[i]);
}
}
OUTPUT :-
Program 8: Write a program to show StringBuffer:-
Source Code :-
class Main
public static void main(String args[])
StringBuffer str = new StringBuffer("Object Language");
[Link]("Original String" +str);
[Link]("Length of String" +[Link]());
String astr = new String([Link]());
int pos = [Link]("Language");
[Link](pos,"Oriented");
[Link]("Modified String:" +str);
[Link](6,'-');
[Link]("String now:" +str);
[Link]("Improve Security");
[Link]("Appended String:" +str);
}
OUTPUT :-