Skip to main content

Posts

Showing posts from 2016

Introduction To C++ Programming - Part 4.

C++ Program To Calculate Determinant Of A Matrix #include<iostream> #include<math.h> using namespace std; double d = 0; double det(int n, double mat[10][10]); double det(int n, double mat[10][10]){ double submat[10][10]; if (n == 2) // set the matrix (must be square) to find determinant. return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1])); else { for (int c = 0; c < n; c++) { int subi = 0; for (int i = 1; i < n; i++) { int subj = 0; for (int j = 0; j < n; j++) { if (j == c) continue; submat[subi][subj] = mat[i][j]; subj++; } subi++; } d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat)); }} return d; }

Java Program To Implement Red Black Tree Operations.

import java.util.Scanner; public class RedBlackTreeA { public static void main(String[] args) { Scanner scan = new Scanner(System.in); RBTree rbt = new RBTree(Integer.MIN_VALUE); char ch; do {       // Deletion of Nodes is not implemented. System.out.println("Red Black Tree Operations:"); System.out.println("1. Insert "); System.out.println("2. Search"); System.out.println("3. Count Nodes"); System.out.println("4. Check Empty"); System.out.println("5. Clear Tree\n"); System.out.print("Enter Your Choice: "); int choice = scan.nextInt(); switch (choice) { case 1 : System.out.print("Enter An Integer To Insert: "); rbt.insert( scan.nextInt() ); break; case 2 : System.out.print("Enter An Integer To Search: "); System.out.println("Search Result : "+ rbt.search( scan.nextInt() )); break;

Java Program To Implement Self-Balancing Binary Search Tree.

import java.util.Scanner; class SBBSTNode { SBBSTNode left, right; int data; int height; public SBBSTNode() { left = null; right = null; data = 0; height = 0; } public SBBSTNode(int n) { left = null; right = null; data = n; height = 0; }} class SelfBalancingBST { private SBBSTNode root;     public SelfBalancingBST() { root = null; } public boolean isEmpty() { return root == null; }

Java Tutorial For Beginners: Part 8.

Java Program To Swap Two Numbers Without Temporary Variable import java.util.Scanner; class SwapNumbers { public static void main(String args[]) { int x, y; System.out.println("Enter x and y:"); Scanner n = new Scanner(System.in); x = n.nextInt(); y = n.nextInt(); System.out.println("Before Swapping:\nx = "+x+"\ny = "+y); x = x + y; y = x - y; x = x - y; System.out.println("After Swapping:\nx = "+x+"\ny = "+y); n.close(); }} Java Program To Swap Two Numbers Using Temporary Variable import java.util.Scanner; class SwapNumbers2 { public static void main(String args[]) { int x, y, temp; System.out.println("Enter x and y:"); Scanner n = new Scanner(System.in); x = n.nextInt(); y = n.nextInt(); System.out.println("Before Swapping:\nx = "+x+"\ny = "+y);

Java Tutorial For Beginners: Part 7.

Java Program To Find Area And Perimeter Of A Rectangle import java.util.*; public class AreaAndPerimeterOfRectangle { private static Scanner s; public static void main(String[] args) { double length, width, Area, Perimeter; s = new Scanner(System.in); System.out.print("Enter The Length Of A Rectangle =  "); length = s.nextDouble(); System.out.print("Enter The Width Of A Rectangle = "); width = s.nextDouble(); Area = length * width; Perimeter = 2 * (length + width); System.out.format("Area Of The Rectangle = %.2f\n",Area); System.out.format("Perimeter Of The Rectangle = %.2f\n", Perimeter); }} Java Program To Find Area And Perimeter Of A Rectangle Using OOP import java.util.Scanner; public class AreaAndPerimeterOfRectangle3a { private static Scanner s; public static void main(String[] args) { double length, width;  s = new Scanner(System.in);

Java Tutorial For Beginners: Part 6.

Java Program To Reverse A Number Using Recursion (OOP) import java.util.Scanner; public class ReverseNumberUsingClassA { private static Scanner sc; public static void main(String[] args) { int Number, Reverse = 0; sc = new Scanner(System.in); System.out.print("Enter Any Number You Want To Reverse: "); Number = sc.nextInt(); ReverseNumberUsingClassB rn = new ReverseNumberUsingClassB(); Reverse = rn.NumberReverse(Number); System.out.format("\nReverse Of %d = %d",Number, Reverse); }} ReverseNumberUsingClassB.java: public class ReverseNumberUsingClassB { int Reverse = 0, Reminder; public int NumberReverse(int Number) { if(Number > 0) { Reminder = Number %10; Reverse = Reverse * 10+ Reminder; NumberReverse(Number /10); } return Reverse; }}

Java Tutorial For Beginners: Part 5.

Problem: Java Program To Print Right Triangle Star Pattern import java.util.*; public class TrianglePattern1 { public static void main(String args[]) { int rows, i, j; Scanner in = new Scanner(System.in); System.out.print("Enter The Number Of Rows: "); rows = in.nextInt(); for(i = 1; i <= rows; i++) { for(j = 1; j <= i; ++j) { /* prints the rows of triangle */ System.out.print("* "); } System.out.print("\n"); /* move to next row */ in.close();  }}} Problem: Java Program To Print Inverted Right Triangle Star Pattern import java.util.Scanner; public class TrianglePattern2 { public static void main(String args[]) { int rows, i, j; Scanner in = new Scanner(System.in); System.out.print("Enter The Number Of Rows: "); rows = in.nextInt();

Java Tutorial For Beginners: Part 4.

Problem: Java Program To Implement Calculator Using Applet. import java.awt.*; import java.awt.event.*; import java.applet.*; public class Calculator extends Applet implements ActionListener { private static final long serialVersionUID = 1L; String msg=" "; int v1,v2,result; TextField t1; Button b[]=new Button[10]; Button add,sub,mul,div,clear,mod,EQ; char OP; public void init() { Color k=new Color(120,89,90); setBackground(k); t1=new TextField(10); GridLayout gl=new GridLayout(3,3); setLayout(gl); for(int i=0;i<10;i++){ b[i]=new Button(""+i); }

Java Tutorial For Beginners: Part 3.

Problem: Java Program To Find Factorial Of A Number import java.util.Scanner; class Factorial { public static void main(String args[]) { int n, c, fact = 1; System.out.print("Enter An Integer To Calculate It's Factorial: "); Scanner s = new Scanner(System.in); n = s.nextInt(); if ( n < 0 ) System.out.println("Number Must Be Non-negative."); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; System.out.println("Factorial Of "+n+" Is = "+fact); s.close(); }}} Problem: Java Program To Find Factorial Of A Number Using Recursion import java.util.*; public class FactorialRecursion { public static void main(String args[]) { int num, factorial = 1; Scanner s = new Scanner(System.in); System.out.print("Enter An Integer To Calculate It's Factorial: "); num = s.nextInt(); if ( num < 0 ) System.out.println("Number Must Be Non-negative.");

A Comprehensive List Of Windows Run Commands.

The run command window is a fast and efficient way to directly access Windows' functions, without sifting through the Control Panel or other menus. I have summarized a comprehensive list of run commands that are tested in Windows 7, 8, and 10. The commands are not case-insensitive. Open the Run command window (press the windows Key + R). Afterward, type any of the following commands and click OK or press Enter. That’s it! Opens Press Windows + R and type: Open Documents Folder documents Open Videos folder videos Open Downloads Folder downloads Open Favorites Folder favorites Open Recent Folder recent Open Pictures Folder pictures Adding a new Device devicepairingwizard About Windows dialog winver Add Hardware Wizard hdwwiz Advanced User Accounts netplwiz Advanced User Accounts azman.msc Backup and Restore s

Java Tutorial For Beginners: Part 2.

Problem: Java Program To Solve Tower Of Hanoi Problem Using Stacks import java.util.*; public class TowerOfHanoiUsingStacks { public static int N; @SuppressWarnings("unchecked") public static Stack<Integer>[] tower = new Stack[4]; public static void main(String[] args) { Scanner scan = new Scanner(System.in); tower[1] = new Stack<Integer>(); tower[2] = new Stack<Integer>(); tower[3] = new Stack<Integer>(); System.out.print("Enter The Number Of Disks: "); int num = scan.nextInt(); N = num; toh(num); scan.close(); } /* Function to push disks into stack */ public static void toh(int n) { for (int d = n; d > 0; d--) tower[1].push(d); display(); move(n, 1, 2, 3); }

Java Tutorial For Beginners: Part 1.

Problem: Java Program To Print “Hello World” class HelloWorld { public static void main(String args []) { System.out.println("Hello Java");  }} Problem: Java Program To Calculate And Display Area Of A Circle import java.util.*; class CalculateCircleAreaExample { private static Scanner s; public static void main(String[] args) { double r, area, pi = 3.14; s = new Scanner(System.in); System.out.print("Enter The Value Of Radius: "); r = s.nextDouble(); area = pi * r * r; // area of circle = pi*r*r System.out.println("The Area Of Circle Of Radius "+r+" = "+area); }} Problem: Java Program To Print Current Date And Time import java.util.Calendar; public class GetCurrentDateTimeExample { public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Year: " + now.get(Calendar.YEAR)); System.out.println("Current Month: " + (n

Introduction To C++ Programming - Part 3.

Problem: A Simple Program To Find The Absolute Value Of An Integer. Method 1:  #include <iostream> using namespace std; int main() { int number; int abs_number; cout << "Enter an integer (positive or negative): " << endl; cin >> number; // Find the absolute value if(number >= 0) { abs_number = number; } else abs_number = -number; // Print out output cout << "The absolute value of " << number << " is " << abs_number; cout << endl; return 0; } Output: Enter an integer (positive or negative): -11 The absolute value of -11 is 11

Introduction To C++ Programming - Part 2.

if statement: #include <iostream> using namespace std; int main()  { int a, b; cout << "Enter first number: " << endl; cin >> a; cout << "Enter second number: " << endl; cin >> b; if(a < b) cout << "First number is less than second.\n"; return 0; } Output: Enter first number: 5 Enter second number: 7 First number is less than second. if-else statement: #include <iostream> using namespace std; int main()  { int a, b; cout << "Enter first number: " << endl; cin >> a; cout << "Enter second number: " << endl; cin >> b;

Introduction To C++ Programming - Part 1.

Hello World: // File name: hello_world.cpp // A simple C++ program which prints "Hello World!" on the screen. #include <iostream>        // header file to support the C++ I/O system. using namespace std;     // telling the compiler to use namespace "std", // where the entire C++ library is declared. int main() { cout << "Hello World!" <<  endl; /* *  cout is the standard output device on the screen. *  << causes the expression on its right to be directed to the device on its left. *  return 0; indicates the successful termination of the "main" function. */ return 0; } Output: Hello World! Variables And Constants: // File name: variable.cpp // Demonstrate the use of variables and constants. #include <iostream> using namespace std; const int CONST_VAL = 5; // declaring a constant. Its value can't be changed.