Record Java Programming
Record Java Programming
Start
Print messsage
End
OutPut
Hello, World!
Expt. No. 01 Page No.: 02
Algorithm:
Result
Output printed successfully
FLOWCHART
Start
n=5
sum=0
i=1
No
i <= n
Yes
sum = sum + i
i=i+1
Print sum
End
OutPut
The sum of the first 5 consecutive positive integers is: 15
Expt. No. 02 Page No.: 03
Write a Java Program to calculate the sum of the first n consecutive positive
integers
int sum = 0;
sum += i;
System.out.println("The sum of the first " + n + " consecutive positive integers is: " + sum);
Algorithm:
Result
Output printed successfully
FLOWCHART
Start
Sum = num1+num2
Close Scanner
End
OUTPUT
Enter the first integer: 8
Enter the second integer: 15
The sum of 8 and 15 is: 23
Write a Program to read 2 Integer numbers from the keyboard and display
their sum on the screen
import java.util.Scanner;
public class SumOfTwoIntegers {
public static void main(String[] args) {
// Create a Scanner object to read input from the keyboard
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the first integer
System.out.print("Enter the first integer: ");
int num1 = scanner.nextInt();
// Prompt the user to enter the second integer
System.out.print("Enter the second integer: ");
int num2 = scanner.nextInt();
// Calculate the sum of the two integers
int sum = num1 + num2;
// Display the sum
System.out.println("The sum of " + num1 + " and " + num2 + " is: " + sum);
Algorithm:
Result
Output printed successfully
Flowchart
Start
Initialize prev=0,
curr=1
i=1
No
i <= 10? End
Yes
OutPut
0 1 1 2 3 5 8 13 21 34
Expt. No. 04 Page No.: 06
Algorithm:
FLOWCHART
Start
i = 100
if
i <= 200
Stop
Yes
if
i % 9 == 0
Yes
Print i
i=i+1
OUTPUT
Multiples of 9 between 100 and 200:
108
117
126
135
144
153
162
171
180
189
198
Write a program to find and print the multiples of 9 between 100 and 200
using for loop
if (i % 9 == 0) {
System.out.println(i);
Algorithm:
FLOWCHART
Start
Input originalNumber
Initialize reversedNumber = 0
Initialize tempNumber = originalNumber
While tempNumber != 0
lastDigit = tempNumber % 10
reversedNumber = reversedNum * 10 + lastDigit
tempNumber = tempNumber / 10
originalNumber == reversedNumber? No
Stop
Stop
OUTPUTS
1. 2.
Enter a number: 121 Enter a number: 123
121 is a palindrome. 123 is not a palindrome.
Expt. No. 06 Page No.: 08
import java.util.Scanner;
Algorithm:
Result
Output printed successfully
FLOWCHART
Start
YES
studentNames.size() > 2
Remove the
name at the
third position (index 2)
Stop
OUTPUT
import java.util.Vector;
Algorithm:
1. Start: Begin the program.
2. Create Vector: Initialize a Vector named studentNames to store student names.
3. Add Initial Names: Add the names "Alice", "Bob", "Charlie", "David", and "Eve" to the
Vector.
4. Add a Name: Add "Frank" at the end of the Vector.
Page No.: 11
5. Delete a Name: Remove the name at the third position (index 2) from the Vector.
6. Display Contents: Print the contents of the Vector.
7. End: Terminate the program.
Result
Output printed successfully
FLOWCHART
Start
Stop
OutPut
1
2
3
Thread suspended
Thread resumed
4
5
Thread stopped
try {
Thread.sleep(3000);
thread.suspend();
System.out.println("Thread suspended");
Thread.sleep(3000);
thread.resume();
System.out.println("Thread resumed");
Thread.sleep(3000);
thread.stop();
System.out.println("Thread stopped");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Page No.: 13
Algorithm
Step 3.1.5: Put the main thread to sleep for another 3000 milliseconds
(3 seconds).
Step 3.1.6: Call thread.resume():
Step 3.1.6.1: Resume the execution of the thread.
Step 3.1.6.2: Print "Thread resumed" to the console.
Step 3.1.7: Put the main thread to sleep for another 3000 milliseconds
(3 seconds).
Step 3.1.8: Call thread.stop():
Step 3.1.8.1: Stop the execution of the thread.
Step 3.1.8.2: Print "Thread stopped" to the console.
Result
Output Printed Successfully
FLOWCHART
Start
Create instance of
ExceptionHandlingDemo
Try block
Call divideNumbers(10, 0)
No
Denominator == 0?
Print Result
Yes
throw ArithmeticException
Catch block
Handle ArithmeticException
Finally block
Print Message
Try block
Call checkAge(15)
Age < 18?
throw IllegalArgumentException
Stop
Expt. No. 09 Page No.: 14
Write a program illustrating the use of exception handling by using try, catch,
finally, throw, and throws blocks
try {
demo.checkAge(15); // This will throw an exception
} catch (IllegalArgumentException e) {
System.out.println("Caught an IllegalArgumentException: " + e.getMessage());
}
}
OUTPUT
Algorithm
Result
Output Printed Successfully
FLOWCHART
Start
Create ByteArrayInputStream
ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer)
While data != -1
Print character (char) data
Read next byte
Close inputStream
inputStream.close()
Stop
OUTPUT
Hello, ByteArrayInputStream!
import java.io.ByteArrayInputStream;
import java.io.IOException;
int data;
while ((data = inputStream.read()) != -1) {
char character = (char) data;
System.out.print(character);
}
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Algorithm
Result
Output printed successfully.