Computer Project Programs
Computer Project Programs
import java.util.Scanner;
Public class MatrixFromUser
{
// Function to read matrix
Public static void readMatrixByUser()
{
int m, n, I, j;
Scanner in = null;
Try
{
In = new Scanner(System.in);
System.out.println(“Enter the number “
+ “of rows of the matrix”);
N= in.nextInt();
System.out.println(“Enter the number “
+ “of columns of the matrix”);
N = in.nextInt();
// Declare the matrix
Int first[][] = new int[m][n];
// Read the matrix values System.out.println(“Enter the elements of the matrix”);
For (I = 0; I < m; i++)
For (j = 0; j < n; j++)
First[i][j] = in.nextInt();
// Display the elements of the matrix
System.out.println(“Elements of the matrix are”);
For (I = 0; I < m; i++) {
For (j = 0; j < n; j++)
System.out.print(first[i][j] + “ “);
System.out.println();
}
}
Catch (Exception e) {
}
Finally {
In.close();
}
}
// Driver code
Public static void main(String[] args)
{
readMatrixByUser();
}
}
Output:
Enter the number of rows of the matrix 2
Enter the number of columns of the matrix 2
Enter the elements of the matrix
1
2
3
4
Elements of the matrix are
12
34
Import java.util.*;
Public class ArrayOfObjects
{
Public static void main(String[] args)
{
// Create an array to hold rectangle’s data.
Rectangle[] rectangles = new Rectangle[5];
Double length; //to hold length of rectangle
Double width; //to hold width of rectangle
// Create a Scanner object for keyboard input.
Scanner console = new Scanner(System.in);
Rectangle[] rectangles = new Rectangle[5];
For (int I = 0; I < 5; i++)
{
System.out.print(“Enter the length of Rectangle “ + (I + 1)
+ “: “);
Length = console.nextDouble();
System.out.print(“Enter the width of Rectangle “ + (I + 1)
+ “: “);
Width = console.nextDouble();
Rectangles[i] = new Rectangle(length, width);
System.out.println();
}
For (int I = 0; I < 5; i++)
{
System.out.println(“Area of Rectangle “ + (I + 1) + “: “
+ rectangles[i].getArea());
}
}
}
Output :
Enter the length of Rectangle 1: 12
Enter the width of Rectangle 1: 3
Class BubbleSort
{
Public static void main(String []args) {
Int n, c, d, swap;
Scanner in = new Scanner(System.in);
System.out.println(“Enter “ + n + “ integers”);
Output:
Class BinarySearch
{
Public static void main(String args[])
{
Int c, first, last, middle, n, search, array[];
System.out.println(“Enter “ + n + “ integers”);
First = 0;
Last = n – 1;
Middle = (first + last)/2;
Output:
Enter number of elements
5
Enter 5 integers
2
5
6
8
9
Enter value to find
5
Import java.util.Scanner;
Public class Edureka
{
Public static void main(String args[])
{
Int n, I, j, space = 1;
System.out.print(“Enter the number of rows: “);
Scanner s = new Scanner(System.in);
N = s.nextInt();
Space = n – 1;
For (j = 1; j<= n; j++)
{
For (I = 1; i<= space; i++)
{
System.out.print(“ “);
}
Space--;
For (I = 1; I <= 2 * j – 1; i++)
{
System.out.print(“*”);
}
System.out.println(“”);
}
Space = 1;
For (j = 1; j<= n – 1; j++)
{
For (I = 1; i<= space; i++)
{
System.out.print(“ “);
}
Space++;
For (I = 1; i<= 2 * (n – j) – 1; i++)
{
System.out.print(“+”);
}
System.out.println(“”);
}
}
}
Output
+
+++
+++++
+++++++
+++++++++
+++++++
+++++
+++
+
Import java.util.Scanner;
Public class JigSawAcademy
{
public static void main(String[] args)
{
For (int I = 5; I >= 0; i–)
{
Int alphabet = 65;
For (int j = 0; j <= I; j++)
{
System.out.print((char) (alphabet + j) + ” “);
}
System.out.println();
}
For (int I = 0; i<= 5; i++)
{
Int alphabet = 65;
For (int j = 0; j <= I; j++)
{
System.out.print((char) (alphabet + j) + ” “);
}
System.out.println();
}
}
}
Output:
ABCDEF
ABCDE
ABCD
ABC
AB
AB
ABC
ABCD
ABCDE
ABCDEF
Import java.util.Scanner;
System.out.println();
}
Sc.close();
}
}
Output
1
22
333
4444
55555
666666
7777777
Class Car{
Public Car()
{
System.out.println(“Class Car”);
}
Public void vehicleType()
{
System.out.println(“Vehicle Type: Car”);
}
}
Class Maruti extends Car{
Public Maruti()
{
System.out.println(“Class Maruti”);
}
Public void brand()
{
System.out.println(“Brand: Maruti”);
}
Public void speed()
{
System.out.println(“Max: 90Kmph”);
}
}
Public class Maruti800 extends Maruti{
Public Maruti800()
{
System.out.println(“Maruti Model: 800”);
}
Public void speed()
{
System.out.println(“Max: 80Kmph”);
}
Public static void main(String args[])
{
Maruti800 obj=new Maruti800();
Obj.vehicleType();
Obj.brand();
Obj.speed();
}
}
Output:
Class Car
Class Maruti
Maruti Model: 800
Vehicle Type: Car
Brand: Maruti
Max: 80Kmph
Class Lamp
{
// stores the value for light
// true if light is on
// false if light is off
Boolean isOn;
// method to turn on the light
Void turnOn() {
isOn = true;
System.out.println(“Light on? “ + isOn);
}
// method to turnoff the light
Void turnOff() {
isOn = false;
System.out.println(“Light on? “ + isOn);
}
}
Class Main
{
Public static void main(String[] args) {
// create objects led and halogen
Lamp led = new Lamp();
Lamp halogen = new Lamp();
// turn on the light by
// calling method turnOn()
Led.turnOn();
// turn off the light by
// calling method turnOff()
Halogen.turnOff();
}
}
Output:
Light on? True
Light on? false
Class Employee{
Int id;
String name;
Float salary;
Void insert(int I, String n, float s) {
Id=I;
Name=n;
Salary=s;
}
Void display(){System.out.println(id+” “+name+” “+salary);}
}
Public class TestEmployee {
Public static void main(String[] args) {
Employee e1=new Employee();
Employee e2=new Employee();
Employee e3=new Employee();
E1.insert(101,”ajeet”,45000);
E2.insert(102,”irfan”,25000);
E3.insert(103,”nakul”,55000);
E1.display();
E2.display();
E3.display();
}
}
Output:
101 ajeet 45000.0
102 irfan 25000.0
103 nakul 55000.0