0% found this document useful (0 votes)
3 views2 pages

Java Lab Record Full

The document is a laboratory record for a Java programming course, detailing various programming experiments including palindrome checking, Fibonacci series generation, factorial computation using command-line arguments, and finding the second largest number from command-line inputs. Each experiment includes sample Java code demonstrating the functionality. The document serves as a practical guide for students to implement and understand basic Java programming concepts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Lab Record Full

The document is a laboratory record for a Java programming course, detailing various programming experiments including palindrome checking, Fibonacci series generation, factorial computation using command-line arguments, and finding the second largest number from command-line inputs. Each experiment includes sample Java code demonstrating the functionality. The document serves as a practical guide for students to implement and understand basic Java programming concepts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

JAVA PROGRAMMING LABORATORY RECORD

Name: Utkarsh
Class: [Link]
University:
Roll No:

1. Basic Java Programming Experiments

1.1 Write a Java program to check whether a given string is a palindrome.

```java
import [Link];

public class PalindromeCheck {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a string: ");
String str = [Link]();
String reversed = new StringBuilder(str).reverse().toString();
if ([Link](reversed)) {
[Link](str + " is a Palindrome.");
} else {
[Link](str + " is not a Palindrome.");
}
[Link]();
}
}
```

1.2 Write a Java program to generate the Fibonacci series up to 'n' numbers.

```java
import [Link];

public class FibonacciSeries {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of terms: ");
int n = [Link]();
int a = 0, b = 1;
[Link]("Fibonacci Series: " + a + " " + b);
for (int i = 2; i < n; i++) {
int c = a + b;
[Link](" " + c);
a = b;
b = c;
}
[Link]();
}
}
```

2. Java Programs Using Command-Line Arguments

2.1 Write a Java program to compute the factorial of a number using command-line
arguments.

```java
public class FactorialCLA {
public static void main(String[] args) {
if ([Link] == 0) {
[Link]("Please provide a number.");
return;
}
int num = [Link](args[0]);
long fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
[Link]("Factorial of " + num + " is: " + fact);
}
}
```

2.2 Write a Java program to accept n numbers from command line arguments, store
them in an array, and find the second largest number.

```java
public class SecondLargestCLA {
public static void main(String[] args) {
if ([Link] < 2) {
[Link]("Provide at least 2 numbers.");
return;
}
int[] arr = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
arr[i] = [Link](args[i]);
}
int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
for (int num : arr) {
if (num > first) {
second = first;
first = num;
} else if (num > second && num != first) {
second = num;
}
}
[Link]("Second Largest: " + second);
}
}
```

3. Object-Oriented Programming Experiments

3.1 Create a Java class Employee...

[Full content continued from previous responses - all sections 1.1 to 7.3]

Note: This is a text representation. For proper .docx, copy this into Microsoft
Word and format with headings, code blocks, etc.

You might also like