Ritikrajproject
Ritikrajproject
Ritikrajproject
ASSIGNMENT
ON
PROGRAMING IN JAVA
BACHELOR OF COMPUTER APPLICATIONS
FROM
Pt. Ravishankar Shukla University Raipur (C.G)
final Year
Year: 2022-2023
Guided by Submitted by
Mr. Mannu Rawani RITIK RAJ
HOD(comp.sc)
CLASS – BCAIII
Submitted to
Pragati College Raipur (C.G)
Pt. Ravishankar Shukla University Raipur (C.G)
ACKNOWLEDEMENT
HOD-Computer Science
Code-
class Encap
{
private int age;
public int getAge()
{
return age;
}
public void setAge( int newAge)
{
age = newAge;
}
}
public class RunEncap
{
public static void main(String args[])
{
Encap encap = new Encap();
encap.setAge(20);
System.out.print(" Age : " + encap.getAge());
}
}
Code-
class Armstrong
{
public static void main(String[] args)
{
int number = 1634, originalNumber, remainder, result = 0, n = 0;
originalNumber = number;
for (;originalNumber != 0; originalNumber /= 10, ++n);
originalNumber = number;
for (;originalNumber != 0; originalNumber /= 10)
{
remainder = originalNumber % 10;
result += Math.pow(remainder, n);
}
if(result == number)
System.out.println(number + " is an Armstrong number.");
else
System.out.println(number + " is not an Armstrong number.");
}
}
Code-
import java.util.Scanner;
public class ExArraySort
{
public static void main(String args[])
{
int n, i, j, temp;
int arr[] = new int[50];
Scanner scan = new Scanner(System.in);
System.out.print("Enter number for the array elements : ");
n = scan.nextInt();
System.out.println("Enter " + n + " Numbers : ");
for (i = 0; i < n; i++)
{
arr[i] = scan.nextInt();
}
System.out.print("Sorting array : \n");
for (i = 0; i < (n - 1); i++)
{
for (j = 0; j < (n - i - 1); j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.print("Sorted List in Ascending Order : \n");
for (i = 0; i < n; i++)
{
System.out.print(arr[i] + " ");
}
}
Code-
import java.util.Scanner;
class Smallnumber
{
public void small()
{
int a, b, c, smallest, temp;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number:");
a = sc.nextInt();
System.out.println("Enter the second number:");
b = sc.nextInt();
System.out.println("Enter the third number:");
c = sc.nextInt();
temp=a<b?a:b;
smallest=c<temp?c:temp;
System.out.println("The smallest number is: "+smallest);
}
public static void main(String[] args)
{
Smallnumber a1 = new Smallnumber();
a1.small();
}
}
Code-
class Count
{
static int wordcount(String a)
{
int count=0;
char ch[]= new char[a.length()];
for(int i=0;i<a.length();i++)
{
ch[i]= a.charAt(i);
if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) )
count++;
}
return count;
}
public static void main(String[] args)
{
String a ="BCA Final Year Student ";
System.out.println(wordcount(a) + " words.");
}
}
Code-
import java.util.Scanner;
public class SumOfDigits
{
public static void main(String args[])
{
int number, digit, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
number = sc.nextInt();
while(number > 0)
{
digit = number % 10;
sum = sum + digit;
number = number / 10;
}
System.out.println("Sum of Digits: "+sum);
}
}
Code-
import java.util.Scanner;
public class LeapYear
{
public static void main(String[] args)
{
int year;
System.out.println("Enter an Year :: ");
Scanner sc = new Scanner(System.in);
year = sc.nextInt();
if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
System.out.println("Specified year is a leap year");
else
System.out.println("Specified year is not a leap year");
}
}
Code-
class Wrapper
{
public static void main(String args[])
{
float p=Float.parseFloat(args[0]);
System.out.println("Principle amount is: "+p);
float r= Float.parseFloat(args[1]);
System.out.println("rate is: "+r);
int t=Integer.parseInt(args[2]);
System.out.println("Enter Time: "+t);
float SI=(p*r*t)/100;
System.out.println("Simple Interest is: "+SI);
}
}
Code-
class Vehicle
{
void run()
{
System.out.println("Vehicle is running");
}
}
class Bike2 extends Vehicle
{
void run()
{
System.out.println("Bike is running safely");
}
Code-
class Box
{
double width, height, depth;
int boxNo;
Box(double w, double h, double d, int num)
{
width = w;
height = h;
depth = d;
boxNo = num;
}
Box()
{
width = height = depth = 0;
}
Box(int num)
{
this();
boxNo = num;
}
public static void main(String[] args)
{
Box box1 = new Box(1);
System.out.println(box1.width);
}
}
Code-
class Animal
{
void eat()
{
System.out.println("eating...");
}
}
class Dog extends Animal
{
void bark()
{
System.out.println("barking...");
}
}
class TestInheritance
{
public static void main(String args[])
{
Dog d=new Dog();
d.bark();
d.eat();
}
}
Code-
class Animal
{
void eat()
{
System.out.println("eating...");
}
}
class Dog extends Animal
{
void bark()
{
System.out.println("barking...");
}
}
class BabyDog extends Dog
{
void weep()
{
System.out.println("weeping...");
}
}
class MultiInheritance
{
public static void main(String args[])
{
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}}
Code-
class Multi extends Thread
{
public void run()
{
System.out.println("thread is running...");
}
public static void main(String args[])
{
Multi t1=new Multi();
t1.start();
}
}
Code-
class Multithreading extends Thread
{
public void run()
{
Try
{
System.out.println("Thread " + Thread.currentThread().getId()+ " is
running");
}
catch (Exception e)
{
System.out.println("Exception is caught");
}
}
public static void main(String[] args)
{
int n = 8;
for (int i = 0; i < n; i++)
{
Multithreading object = new Multithreading();
object.start();
}
}
}
Code-
class Prime
{
public static void main(String args[])
{
boolean b=true;
for(int i= 1; i<=50;i++)
{
b=true;
for(int j=2;j<=i/2;j++)
{
if(i%j==0)
b=false;
}
if(b)
System.out.println("Prime Number"+i);
}
}
}
Code-
import java.io.*;
class Bytewrite
{
public static void main(String args[])
{
try
{
FileOutputStream a= new
FileOutputStream("C:\\Users\\ashwa\\Declare.txt");
BufferedOutputStream b = new BufferedOutputStream(a);
String st ="Java is a programming language";
byte by[]=st.getBytes();
b.write(by);
b.close();
a.close();
System.out.println("Done");
}
catch(IOException e1)
{
System.out.println("Error");
}
}
}
int i;
while((i=c.read())!=-1)
{
System.out.print((char)i);
}
c.close();
d.close();
}
catch(IOException e)
{
System.out.println(e);
}
}}