Java File
Java File
B.TECH (AI&DS)
OOPs With Java (PRACTICAL)
Course:- B.TECH
Branch:-AI&DS(4TH sem)
_____
2
INDEX:-
S.NO. NAME OF PROGRAM SIGN
1. Write a program to print “Hello World”
29. Write a program in which read a string and reverse its character
3
Output :-
Output:-
5
4. Write a program to take a number as input and print its multiplication table upto 10
Output :-
8
Output :-
Output :-
11
}
Output:-
14
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]+" ");
}
System.out.println();
}
}
}
Output :-
15
Output :-
16
Output :-
17
Output :-
Output:-
18
Output :-
19
Output :-
20
Output:-
21
}
}
22
Output :-
Output :-
23
Output :-
24
Output :-
25
Output :-
23.Write a program to create and import a package to calculate marks and print grade
of student
➔ Creating package:-
package data; import java.util.*;
public class mark
{
public void input()
{
int m, p, c, e, h;
String name;
Scanner sc= new Scanner(System.in);
System.out.println("Enter name and marks of 5 subject"); name=
sc.nextLine(); m= sc.nextInt(); p= sc.nextInt(); c= sc.nextInt(); h=
sc.nextInt(); e= sc.nextInt();
System.out.println("name of student : "+name);
System.out.println("Marks of 5 subject :- ");
System.out.println("english :"+e);
System.out.println("maths :"+m);
System.out.println("physics :"+p);
System.out.println("chemistry :"+c);
System.out.println("hindi :"+h); int tot= (e+m+p+c+h);
int g= tot/5;
System.out.println("Total Marks :"+tot); if(g>=60)
26
Output:-
27
Output :-
28
25. Write a program for handling the uncaught exception using finally
import java.util.*; public class finallyex
{
public static void main(String []args) throws Exception
{
System.out.println("Enter two number"); Scanner sc= new
Scanner(System.in);
int a= sc.nextInt();
int b= sc.nextInt();
try{ int c= a/b;
System.out.println("a/b = "+c);
}
catch(Exception e)
{
System.out.println("Arithmetic Exception - Divide by 0");
} finally{
System.out.println("Finally
Bye");
}
}
}
Output :-
29
Output :-
➔ Java file :-
import java.awt.*; import java.awt.event.*;
{ int x, y, z;
setBackground(Color.yellow); add(l1);
add(t1); add(l2);
add(t2); add(b);
b.addActionListener(this);
x= Integer.parseInt(t1.getText()); y=
➔ HTML file :-
<html>
<body>
</applet>
</body>
</html>
31
Output :-
Output :-
32
B. Hashset :-
import java.util.*;
class hashex
{
public static void main(String []args)
{
HashSet<String> h= new HashSet<String>(); h.add("Mango");
h.add("Apple");
h.add("Guava");
h.add("Grapes");
h.add("Banana"); Iterator<String> i= h.iterator();
while(i.hasNext())
{
System.out.println(i.next());
}
}
}
Output :-
33
# output