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);
}
}
}
Anny Lumbanraja
Minggu, 26 Mei 2013
Console Random Number 1-6...!!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RandomNumber
{
class Program
{
static void Main()
{
Random();
Random();
Random();
Random();
Random();
Random();
}
static Random MyRandom = new Random();
static void R()
{
for(int i = 0; i < 600; i++)
{
double value;
double n = 0.5 + MyRandom.NextDouble() * 6.0-0.5;
value = Math.Round(n);
Console.WriteLine(value);
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RandomNumber
{
class Program
{
static void Main()
{
Random();
Random();
Random();
Random();
Random();
Random();
}
static Random MyRandom = new Random();
static void R()
{
for(int i = 0; i < 600; i++)
{
double value;
double n = 0.5 + MyRandom.NextDouble() * 6.0-0.5;
value = Math.Round(n);
Console.WriteLine(value);
}
Console.ReadLine();
}
}
}
Rabu, 10 April 2013
Program that emulates a Calculator ^^
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calculation
{
class CalculateNumber
{
int Number1, Number 2;
char option;
int Result;
public void Number ()
{
Console.WriteLine("Enter the First Number");
Number1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Second nummber");
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("Invailid Option");
break;
}
Console.ReadLine();
}
}
class ClassMain
{
static void Main (string[] args)
{
CalculateNumber obj = new CalculateNumber();
obj.Number();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calculation
{
class CalculateNumber
{
int Number1, Number 2;
char option;
int Result;
public void Number ()
{
Console.WriteLine("Enter the First Number");
Number1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Second nummber");
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("Invailid Option");
break;
}
Console.ReadLine();
}
}
class ClassMain
{
static void Main (string[] args)
{
CalculateNumber obj = new CalculateNumber();
obj.Number();
}
}
}
Selasa, 26 Maret 2013
Differences Between Java and C#
A. Java Primitive Types
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.
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.
Langganan:
Komentar (Atom)