Rina's Blog
Senin, 29 Juni 2015
Senin, 03 Juni 2013
Permutation in Cards (C#)
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);
}
}
}
Summary Constractor, Destructor, and Polymorphism
Summary Constractor And 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.
- 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.
What is the triangle's Formula by Using Java?
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);
}
}
Senin, 08 April 2013
C# CODE for CALCULATOR
using System;
namespace Calculation
{
class CalculateNumber
{
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 ofmultiplication 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)
{
CalculateNumber obj = new CalculateNumber();
obj.Number();
}
}
namespace Calculation
{
class CalculateNumber
{
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 ofmultiplication 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)
{
CalculateNumber obj = new CalculateNumber();
obj.Number();
}
}
C# better than JAVA ??
JAVA
Not everything in Java is an object. There is a special group of data types (also known as primitive types)
that will be used quite often in your programming. For performance reasons, the designers of the Java language
decided to include these primitive types.
Creating an object using new isn't very efficient because new will place objects on the heap. This approach would be very costly for small and simple variables. Instead of create variables using new, Java can use primitive types to create automatic variables that are not references. The variables hold the value, and it's place on the stack so its much more efficient.
Java determines the size of each primitive type. These sizes do not change from one machine architecture to another (as do in most other languages). This is one of the key features of the language that makes Java so portable.
Take note that all numeric types are signed. (No unsigned types).
Finally, notice that each primitive data type also has a "wrapper" class defined for it. This means that you can create a "nonprimitive object" (using the wrapper class) on the heap (just like any other object) to represent the particular primitive type.
For example:int i = 5; Integer I = new Integer(i);ORInteger I = new Integer(5);
Data Types and Data Structures
Primitive Type | Size | Minimum Value | Maximum Value | Wrapper Type |
char | 16-bit | Unicode 0 | Unicode 216-1 | Character |
byte | 8-bit | -128 | +127 | Byte |
short | 16-bit | -215 (-32,768) |
+215-1 (32,767) |
Short |
int | 32-bit | -231 (-2,147,483,648) |
+231-1 (2,147,483,647) |
Integer |
long | 64-bit | -263 (-9,223,372,036,854,775,808) |
+263-1 (9,223,372,036,854,775,807) |
Long |
float | 32-bit | 32-bit IEEE 754 floating-point numbers | Float | |
double | 64-bit | 64-bit IEEE 754 floating-point numbers | Double | |
boolean | 1-bit | true or false | Boolean | |
void | ----- | ----- | ----- | Void |
C#
C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type.
For example:
static void Main(){int i = 10;object o = i;System.Console.WriteLine(o.ToString());}C# PRIMITIVE TYPEFCL DATA TYPEDESCRIPTIONobjectSystem.ObjectUltimate base type of all other types.stringSystem.StringA sequence of Unicodecharacters.decimalSystem.DecimalPrecise decimal with 28 significant digits.boolSystem.BooleanA value represented as true or false.charSystem.CharA 16-bit Unicode character.byteSystem.Byte8-bit unsigned integral type.sbyteSystem.SByte8-bit signed integral type.shortSystem.Int1616-bit signed integral type.intSystem.Int3232-bit signed integral type.System.Int6464-bit signed integral type.ushortSystem.UInt1616-bit unsigned integral type.uintSystem.UInt3232-bit unsigned integral type.ulongSystem.UIint6464-bit unsigned integral type.single (float)System.SingleSingle-precision floating-point type.doubleSystem.DoubleDouble-precision floating-point type.
Langganan:
Postingan (Atom)