[夏肇毅知識運算網 Mark Hsia's Knowledge Computing Web]
一次學會五種程式設計語言- BASIC,C++, JAVA, C# 與 PHP
電腦程式語言看起來不同, 但其實他們都可以做相同的工作. 我們可以針對主要的課題一起學習.
Computer programming languages from BASIC,C++, JAVA, C# to PHP seem different, but actually they can do the same task. We can study them all together under some basic topics.
開始就是了解像 a=a+1 的賦值指令. 這不是方程式, 而是計算a+1的結果, 然後放回 a.
The first lesson of coding to understand assignment like a=a+1. This is not an equation. It simply means compute a+1 and put the result back to a.
Here we list some statements of assignment in five different programming languages: BASIC,C++, JAVA, C# and PHP.
' Value Assignment
iA = 1*2+3/4-5
iB = 1*(2+3)/4-5
iC =iA Mod 2
' Print iA,iB,iC
' String Assignment
sS="abc"
' String Catenation
sS=sS+"<>"
sS=sS+"def"
' Print sS
BASIC:
' *******************************************
' Assignment Statement BASIC
' *******************************************
Sub AssignmentStatement()
Dim iA as Integer
Dim iB as Integer
Dim iC as Integer
Dim sS as String
' Value Assignment
iA = 1*2+3/4-5
iB = 1*(2+3)/4-5
iC =iA Mod 2
Debug.Print " ";iA;
Debug.Print " ";iB;
Debug.Print " ";iC;
Debug.Print
' String Assignment
sS="abc"
' String Catenation
sS=sS+"<>"
sS=sS+"def"
Debug.Print " ";"sS=";
Debug.Print " ";sS;
Debug.Print
End Sub
C++:
/* ******************************************* */
/* Assignment Statement C++ */
/* ******************************************* */
void AssignmentStatement() {
int iA;
int iB;
int iC;
char* sS;
/* Value Assignment */
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
printf(" %d" , iA);
printf(" %d" , iB);
printf(" %d" , iC);
printf("\n" );
/* char* Assignment */
vstrcpy((char**)&sS, "abc");
/* char* Catenation */
vstrcat((char**)&sS, "<>");
vstrcat((char**)&sS, "def");
printf(" %s" , "sS=");
printf(" %s" , sS);
printf("\n" );
vfree((char*)sS);
}
JAVA:
// *******************************************
// Assignment Statement JAVA
// *******************************************
public void AssignmentStatement() {
int iA;
int iB;
int iC;
String sS = null;
// Value Assignment
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
System.out.print(" "+iA );
System.out.print(" "+iB );
System.out.print(" "+iC );
System.out.println("");
// String Assignment
sS="abc";
// String Catenation
sS=sS+"<>";
sS=sS+"def";
System.out.print(" "+"sS=" );
System.out.print(" "+sS );
System.out.println("");
}
C#:
/* ******************************************* */
/* Assignment Statement C# */
/* ******************************************* */
public void AssignmentStatement() {
int iA;
int iB;
int iC;
String sS = null;
/* Value Assignment */
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
Console.Write(" "+iA);
Console.Write(" "+iB);
Console.Write(" "+iC);
Console.WriteLine("");
/* String Assignment */
sS="abc";
/* String Catenation */
sS=sS+"<>";
sS=sS+"def";
Console.Write(" "+"sS=");
Console.Write(" "+sS);
Console.WriteLine("");
}
PHP:
/* ******************************************* */
/* Assignment Statement PHP */
/* ******************************************* */
function AssignmentStatement() {
/* Value Assignment */
$iA = 1*2+3/4-5;
$iB = 1*(2+3)/4-5;
$iC =$iA % 2;
echo " ".$iA;
echo " ".$iB;
echo " ".$iC;
echo "";
/* String Assignment */
$sS="abc";
/* String Catenation */
$sS.="<>";
$sS.="def";
echo " "."sS=";
echo " ".$sS;
echo "";
}