JAVA PROGRAMMING LAB
NCS-352
SUBMITTED BY: SUBMITTED TO:
JANHVI NARAYAN ER. NITIKA GUPTA
CSE(AI)-I (P2)
2310013155050
FACULTY OF ENGINEERING AND TECHNOLOGY
UNIVERSITY OF LUCKNOW
INDEX
Sr. Practical Name Date of Practical Signature
No.
DATA STRUCTURE LAB
NCS-351
SUBMITTED BY: SUBMITTED TO:
JANHVI NARAYAN ER. OM PRAKASH SINGH
CSE(AI)-I (P2)
2310013155050
FACULTY OF ENGINEERING AND TECHNOLOGY
UNIVERSITY OF LUCKNOW
INDEX
Sr. Practical Name Date of Practical Signature
No.
NUMERICAL TECHNIQUES LAB
NCS-353
SUBMITTED BY: SUBMITTED TO:
JANHVI NARAYAN ER. ROHIT SRIVASTAV
CSE(AI)-I (P2)
2310013155050
FACULTY OF ENGINEERING AND TECHNOLOGY
UNIVERSITY OF LUCKNOW
INDEX
Sr. Practical Name Date of Practical Signature
No.
THEORY OF AUTOMATA LAB
NCS-354
SUBMITTED BY: SUBMITTED TO:
JANHVI NARAYAN DR. PRIYANKA JAISWAL
CSE(AI)-I (P2)
2310013155050
FACULTY OF ENGINEERING AND TECHNOLOGY
UNIVERSITY OF LUCKNOW
INDEX
Sr. Practical Name Date of Practical Signature
No.
PROGRAM – 1
Question: Write a program to check whether a number is a
Palindrome number or not.
Input:
import [Link].*;
class program
{public static void main(String args[])
{ Scanner sc= new Scanner([Link]);
int num, sum=0, rem, temp;
[Link]("Enter any number to check if it is a Palindrome or not: ");
num=[Link]();
temp=num;
while(temp>0)
{ rem=temp%10;
sum=sum*10+rem;
temp=temp/10;}
if(sum==num){
[Link]("The number is a Palindrome number.");
}else
{[Link]("The number is not a Palindrome number.");
}}}
Output: //Janhvi Narayan
PROGRAM – 2
Question: Write a program to find the sum of the digits of a
number.
Input:
import [Link].*;
class SumofDigits
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter a number: ");
int num=[Link]();
int sum=0;
while(num!=0)
{
sum+=num%10;
num/=10;
}
[Link]("The sum of digits is:"+sum);
}
}
Output: //Janhvi Narayan
PROGRAM – 3
Question: Write a program to find the sum and average of two
numbers.
Input:
import [Link];
class Sum_Avg
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
float a,b;
[Link]("Enter the 1st number: ");
a=[Link]();
[Link]("Enter the 2nd number: ");
b=[Link]();
float sum=a+b;
[Link]("The sum is: "+sum);
float avg=sum/2;
[Link]("The average is: "+avg);
}
}
Output: //Janhvi Narayan
PROGRAM – 4
Question: Write a program to compute the sum of the first and last
digits of a number.
Input:
import [Link].*;
class Sum_first_last
{public static void main(String args[])
{ Scanner sc=new Scanner([Link]);
[Link]("Enter any number: ");
int num=[Link]();
int temp=num;
int last=num%10;
while(num>=10)
{num/=10;}
int first=num;
int sum=first+last;
[Link]("The sum of the first and last digit: "+sum);
}
}
Output: //Janhvi Narayan
PROGRAM – 5
Question: Write a program to swap two numbers without using
third variable.
Input:
import [Link].*;
class Swap
{ public static void main(String a[])
{ [Link]("Enter the value of x and y");
Scanner sc = new Scanner([Link]);
/*Define variables*/
int x = [Link]();
int y = [Link]();
[Link]("Before swapping numbers: "+x +" "+ y);
/*Swapping*/
x = x + y;
y = x - y;
x = x - y;
[Link]("After swapping: "+x +" " + y);
}
}
Output: //Janhvi Narayan
PROGRAM – 6
Question: Write a program to check whether a number is
Armstrong number or not.
Input:
import [Link];
public class ArmstrongNumber
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
if (isArmstrong(number)) {
[Link](number + " is an Armstrong number.");}
else {[Link](number + " is not an Armstrong number.");}}
private static boolean isArmstrong(int number) {
int originalNumber = number;
int numDigits = [Link](number).length();
int sum = 0;
while (number > 0) {
int digit = number % 10;
sum += [Link](digit, numDigits);
number /= 10;}
return sum == originalNumber;}}
Output: //Janhvi Narayan
PROGRAM – 7
Question: Write a program to print Floyd’s Triangle.
1
23
456
.............. 91
Input:
public class patternOf1_91 {
public static void main(String[] args) {
int num=1 ,row=1;
while(num<=91){
for(int col=1;col<=row;col++){
[Link](num+" ");
num++;}
[Link]();
row++; }}}
Output: //Janhvi Narayan
PROGRAM – 8
Question: Write a program to print given * pattern.
*
**
***
Input:
public class StarPattern {
public static void main(String[] args) {
int rows = 3; // Number of rows in the pattern
// Outer loop for rows
for (int i = 1; i <= rows; i++) {
// Inner loop for printing stars in each row
for (int j = 1; j <= i; j++) {
[Link]("* ");}
[Link](); // Move to the next line}}}
Output: //Janhvi Narayan
PROGRAM – 9
Question: Write a program to check whether a number is even
number or not.
Input:
import [Link];
public class EvenOddChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
if (number % 2 == 0) {
[Link](number + " is an even number.");
} else {
[Link](number + " is an odd number.");
}
[Link]();
}
}
Output: //Janhvi Narayan
PROGRAM – 10
Question: Write a program which prints your name using
command line arguments.
Input:
public class PrintName {
public static void main(String[] args) {
// Check if any arguments were passed
if ([Link] > 0) {
[Link]("Your name is: " + args[0]+" "+args[1]);
} else {
[Link]("No name provided!");
}
}
}
Output: //Janhvi Narayan