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[])
System.out.println("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 = args.length;
System.out.println("No. of arguments are: " + count);
while(i<count)
s = args[i];
i++;
System.out.println("Java is "+s);
OUTPUT :-
Program 3: Write a program to find Largest number using Scanner Class-
Source Code :-
import java.util.*;
class Maxnumber
public static void main(String args[])
Scanner x = new Scanner(System.in);
System.out.println("Enter the values of a, b and c");
int a = x.nextInt();
int b = x.nextInt();
int c = x.nextInt();
if(a>b && a>c)
System.out.println("Largest number is " +a);
else if(b>a && b>c)
System.out.println("Largest number is " +b);
else
System.out.println("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 java.util.*;
public class ListSorting
public static void main(String args[])
int a[] = new int[5];
Scanner sc = new Scanner(System.in);
System.out.println("Enter the values");
for(int i=0; i<5; i++)
a[i] = sc.nextInt();
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++)
System.out.println(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];
System.out.print(c[i][j]+" ");
}//end of j loop
System.out.println();//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 < a.length; i++)
for(int j=0; j < a[i].length; j++)
a[i][j] = count++;
for(int i=0; i < a.length; i++)
for(int j=0; j < a[i].length; j++)
System.out.print(a[i][j] + " ");
}
System.out.println();
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 = name.length;
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++)
System.out.println(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");
System.out.println("Original String" +str);
System.out.println("Length of String" +str.length());
String astr = new String(str.toString());
int pos = astr.indexOf("Language");
str.insert(pos,"Oriented");
System.out.println("Modified String:" +str);
str.setCharAt(6,'-');
System.out.println("String now:" +str);
str.append("Improve Security");
System.out.println("Appended String:" +str);
}
OUTPUT :-