Angry Birds

Permutation in Cards (C#)

Label: ,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class Program
{

    class Permutation
    {

        private void swap(ref char a, ref char b)
        {

            if (a == b) return;

            a ^= b;

            b ^= a;

            a ^= b;

        }

        public void setper(char[] list)
        {

            int x = list.Length - 1;

            go(list, 0, x);

        }

        private void go(char[] list, int k, int m)
        {

            int i;

            if (k == m)
            {

                Console.Write(list);

                Console.WriteLine(" ");

            }

            else

                for (i = k; i <= m; i++)
                {

                    swap(ref list[k], ref list[i]);

                    go(list, k + 1, m);

                    swap(ref list[k], ref list[i]);

                }
            Console.ReadLine();
        }

    }

    class Class1
    {

        static void Main()
        {

            Permutation p = new Permutation();

            string c = "123456";

            char[] c2 = c.ToCharArray();



            p.setper(c2);

        }

    }
}

Rolling A Dice in C#

Label: ,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dice
{

    class Program
    {


        static void Main()
        {
            F();
            F();
            F();
            F();
            F();
            F();
        }

        static Random rnd = new Random();
        static void F()
        {

            for (int i = 0; i < 600; i++)
            {
                double value;
                double n = 0.5 + rnd.NextDouble() * (6.0 - 0.5);
                value = Math.Round(n);
                Console.WriteLine(value);
            }

            Console.ReadLine();
        }

    }
}

Summery Constractor, Destructor, and Polymorphism

Label:

Summary Constractor n Destructor

- A constructor is used to initialize the members of the class.
- There are two types of constructors, instance constructors and static constructors.
- Instance constructors are used to initialize data members of the class.
- Static constructors are used to initialize the static variables of a class.
- Destructors are used to release the instance of a class from memory.
- Garbage collection is a process that automatically frees the memory of objects that are no
more in use.
- Objects get destroyed: It does not specify when the object shall be destroyed.
- Only unused objects are destroyed: An object is never destroyed if it holds the
reference of another object.
- The Finalize() destructor is a special method that is called from the class to which it
belongs or from the derived classes. The Finalize() destructor is called after the last
reference to an object is released from the memory.
- The Dispose() method is called to release a resource, such as a database connection, as
soon as the object using such a resource is no longer in use.


Summary Polymorphism

- Static Polymorphism refers to an entity.
- Function Overloading allows using the same name for two or more function.
- The type, sequence, or number of parameters for a function is called the function signature.
- Operator overloading allows user defined types such as structures and classes.
- Dynamic Polymorphism function execution is made at runtime and it compared to static polymorphism.
- Abstract classes consist of abstract class numbers.
- Virtual function is appear to be present in some parts of the program.

Triangle's Formula Using Java

Label: ,

Now, I wanna tell you how to find the value of triangle side. Hmm.. Maybe I'm not good in math, but I always try to find it as long as I can. So, if you find any wrong in my syntax, please put your comment.
Hehe.. Here is the syntax... Lets check it out!


package chacam.main;

public class SisiSegitigaSembarang
{
    public static void main(String[] args)
    {
        int a,b,c;
        double degreeA, degreeB, degreeC;

        a = 8;

        degreeA = 65;
        degreeB = 95;
        degreeC = 20;

        b = (int) ((a) * Math.sin(degreeB) / (Math.sin(degreeA)));

        System.out.println("Nilai sisi b = "+b);

        c = (int) ((b)*Math.sin(degreeC)/(Math.sin(degreeB)));

        System.out.println("Nilai sisi c = "+c);

    }
}



A Simple Calculator Using C#

Label: ,

This time, I wanna share the the syntax to make a simple calculator using C#.
Here it is..!



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Calculator
{
    class Calculating
    {
        int Number1, Number2;
        char option;
        int Result;
        public void Number()
        {
            Console.WriteLine("Enter the First number");
            Number1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the second number");
            Number2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Main Menu");
            Console.WriteLine("1.Addition");
            Console.WriteLine("2.Subtraction");
            Console.WriteLine("3.Multiplication");
            Console.WriteLine("4.Division");
            Console.WriteLine("Enter the Operation you want to perform");
            option = Convert.ToChar(Console.ReadLine());
            switch (option)
            {
                case '1':
                    Result = Number1 + Number2;
                    Console.WriteLine("The result of addition is:{0}", Result);
                    break;
                case '2':
                    Result = Number1 - Number2;
                    Console.WriteLine("The result of subtraction is:{0}", Result);
                    break;
                case '3':
                    Result = Number1 * Number2;
                    Console.WriteLine("The result of multiplication is:{0}", Result);
                    break;
                case '4':
                    Result = Number1 / Number2;
                    Console.WriteLine("The result of division is:{0}", Result);
                    break;
                default:
                    Console.WriteLine("Invalid Option");
                    break;
            }
            Console.ReadLine();
        }
    }
}

class ClassMain
{
    static void Main(string[] args)
    {
        Calculator.Calculating obj = new Calculator.Calculating();
        obj.Number();
    }
}

Java VS C# (C-Sharp) ! Which one is the WINNER ?!

Label: ,

Hello Everybody!
Its very long time no posting here.
This time I'll try to explain about differences between Mr.Java & Mr.C-Sharp
Ok ! Lets check it out!

A. Java Primitive Types
There are 4 datatype on Java Programming Language.
Here it is...

1. Logical --- boolean
 Logical values are represented using the boolean type,which takes one of two values : true or false.
Example :
boolean result = true;
This example is to declare a variable which named by "result" as boolean datatype, and give it true value.

2. Textual --- char
 This type is representative by single unicode.
You must enclose a char literal in single quotes(' ').
Example :
'a'  // The letter a
'\t'  // A tab

3. Integral --- byte, short, int, and long
 It using decimal, octal, and hexadecimal.
 byte = 8 bits
 short = 16 bits
 int = 32 bits
 long = 64 bits
Example :
2 // decimal for integer 2
077 // 0 indicates an octal value
0xBAAC // 0x indicates a hexadecimal value

4. Floating Points --- float and double
 "double" is the datatype default.
 E or e  ==> add exponential value
 F or f ==> float
 D or d ==> double
Example :
3.14
6.02E23 ==> 23 after E has a positive value, equivalent with 6.02E+23


B. C# Primitive Types


 Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type.
Example :
        static void Main()
{
    int i = 10;
    object o = i;
    System.Console.WriteLine(o.ToString());
}

>> Type of Data Type

- Value Types
   They directly content data. The example are char, int, and float, which can be used for storing alphabets, integers, and floating point numbers.
- Reference Type
   They contain a reference to the variables which are stored in memory. The example is string datatype.


Ok! Thats all a little explaination about Java & C# data type.
From that, we can take some differences between Java and C#
Here it is.

Differences between Java and C# :
- To compare string values in Java,
developers need to call the equals method on a string type
as the == operator compares reference types by default.
In C#, developers can use the == or != operators to compare string values directly.
- Java's boolean is called bool in C#.
- C# supports unsigned in addition to the signed integer types.
Java does not feature unsigned integer types.


C# so POPULAR?? Why?
Its because :
It really is a great platform for programming. There are numerous improvements over Java, such as:
  1. Value Types
  2. Properties
  3. Delegates and Events
  4. Global Assembly Cache
  5. Runtime Generic Support
It's constantly evolving, both in terms of library support and new language features. 
Example:
  1. LINQ (it will change the way you iterate a collection!)
  2. Lambda Expressions
  3. Closure


Pseudocode Deret fibonacci

Label:

begin
        int j = 1;
        int k = 1;
        int i;
        int h;
        int iLimit;

        print ("masukan limit")
        accept iLimit
        
        if ( iLimit = 1 )
        { print "0"
        }
        else
          { print "0"
             print (" ")
                for ( j= 2 ; j < = iLimit ; j ++ )
               { h = j + k;
                  j = k;
                  k = h;
               }
           }
         end if
end

Pseudocode Segitiga Pascal

Label: ,


Int i = 1;
Int j = 1;
Int k = 1; 
Int iBil;

Begin 

print("Masukkan Level: "); 

for (i=0; i&lt;=iBil; i++) 
{
   for (int j = 1; j &lt;= iBil - i; j++)
   print(" ");
    { 
       for (k = 1; k &lt;= i; k++) 
         {
             if (k==0||i==k)
             print(i + " ");
          }
    } 
  printnl(); 
End