JAVA PROGRAMMING LAB - Removed
JAVA PROGRAMMING LAB - Removed
Page
S.NO Date Title sign
.No
An integer and then prints out all
1. the prime numbers up to that
Integer
2. To multiply two given matrices
That displays the number of
3.
characters, lines and words in a text
Generate random numbers between
two given limits using Random
4.
class and print messages according
to the range of the value generated
String Manipulation using
5.A Character Array,
“String Length”
String Manipulation using
Character Array,
5.B
“Finding a character at a
particular position”
String Manipulation using
5.C Character Array,
“Concatenating two strings”
String operations using String
6.A
class, “String Concatenation”
String operations using String
6.B
class, “Search a substring”
String operations using String
6.C class, “To extract substring from
given string”
String operations using
7.A StringBuffer class,
“Length of a string”
3
String operations using
StringBuffer class,
7.B “Reverse a string”
String operations using
StringBuffer class,
7.C
“Delete a substring from the
given string”
That implements a multi-thread
application that has three threads.
First thread generates random
integer every 1 second and if the
8. value is even, second thread
computes the square of the number
and prints. If the value is odd, the
third thread will print the value of
cube of the number.
which uses the same method
asynchronously to print the
9. numbers 1 to 10 using Thread-0
and to print 90 to 100 using
Thread-1
Write a program to demonstrate the
use of following exceptions.
a) Arithmetic Exception
4
SOURCE CODING:
6
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
7
SOURCE CODING:
int a[][]={{1,1,1},{2,2,2},{3,3,3}};
int b[][]={{1,1,1},{2,2,2},{3,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();//new line
}
9
OUTPUT:
666
12 12 12
18 18 18
RESULTS:
Thus, the above java program executed successfully and output verified.
10
SOURCE CODING:
import java.io.*;
String line;
int wordCount = 0;
int characterCount = 0;
int paraCount = 0;
int whiteSpaceCount = 0;
int sentenceCount = 0;
if (line.equals("")) {
paraCount += 1;
} else {
characterCount += line.length();
12
String words[] = line.split("\\s+");
wordCount += words.length;
whiteSpaceCount += words.length - 1;
sentenceCount += sentence.length;
if (sentenceCount >= 1) {
paraCount++;
13
OUTPUT:
Number of paragraphs = 4
RESULTS:
Thus, the above java program executed successfully and output verified.
14
SOURCE CODING:
import java.io.*;
import java.util.*;
class GFG {
int max=100,min=50;
16
OUTPUT:
76
89
53
RESULTS:
Thus, the above java program executed successfully and output verified.
17
SOURCE CODING:
System.out.println(s.length());
19
OUTPUT:
26
RESULTS:
Thus, the above java program executed successfully and output verified.
20
SOURCE CODING:
int position = 7;
} else {
22
OUTPUT:
Character at position 7: W
RESULTS:
Thus, the above java program executed successfully and output verified.
23
SOURCE CODING:
25
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
26
SOURCE CODING:
System.out.println(result);
28
OUTPUT:
Hello, World!
RESULTS:
Thus, the above java program executed successfully and output verified.
29
SOURCE CODING:
// Example string
String mainString = "The quick brown fox jumps over the lazy dog.";
if (mainString.contains(substring)) {
} else {
31
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
32
SOURCE CODING:
// Input string
// Extracting a substring
34
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
35
SOURCE CODING:
// Input string
37
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
38
SOURCE CODING:
// Input string
stringBuffer.reverse();
40
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
41
SOURCE CODING:
// Input string
// Substring to delete
mainString.delete(mainString.indexOf(substringToDelete),
mainString.indexOf(substringToDelete) + substringToDelete.length());
43
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
44
SOURCE CODING:
import java.util.Random;
int x;
Square(int n)
x = n;
int sqr = x * x;
int x;
Cube(int n)
x = n;
int cub = x * x * x;
s.start();
c.start();
try {
Thread.sleep(1000);
{
48
System.out.println(ex);
n.start();
49
OUTPUT:
Square of 42 = 1764
Cube of 42 = 74088
Square of 57 = 3249
Cube of 57 = 185193
Square of 89 = 7921
Cube of 89 = 704969
Square of 15 = 225
Cube of 15 = 3375
Square of 37 = 1369
Cube of 37 = 50653
Square of 61 = 3721
Cube of 61 = 226981
Square of 43 = 1849
Cube of 43 = 79507
Cube of 99 = 970299
Square of 39 = 1521
Cube of 39 = 59319
Square of 56 = 3136
Cube of 56 = 175616
RESULTS:
Thus, the above java program executed successfully and output verified.
51
SOURCE CODING:
package com.xxxx.simpleapp;
import java.util.ArrayList;
import java.util.List;
@Override
54
public void run() {
synchronized (monitor) {
try {
while (true) {
while (monitor.currentTaskValue % 10 != modValue) {
monitor.wait();
}
if (monitor.currentTaskValue == 101) {
break;
}
System.out.println(Thread.currentThread().getName() + " : "
+ monitor.currentTaskValue + " ,");
monitor.currentTaskValue = monitor.currentTaskValue + 1;
monitor.notifyAll();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
55
OUTPUT:
Thread-1 : 1 ,
Thread-2 : 2 ,
Thread-3 : 3 ,
Thread-4 : 4 ,
Thread-5 : 5 ,
Thread-6 : 6 ,
Thread-7 : 7 ,
Thread-8 : 8 ,
Thread-9 : 9 ,
......
.....
...
Thread-4 : 94 ,
Thread-5 : 95 ,
Thread-6 : 96 ,
Thread-7 : 97 ,
Thread-8 : 98 ,
Thread-9 : 99 ,
Thread-0 : 100 ,
RESULTS:
Thus, the above java program executed successfully and output verified.
56
SOURCE CODING:
59
}
}
}
60
OUTPUT:
RESULTS:
Thus, the above java program executed successfully and output verified.
61