定义圆的类模板,其中包含一个求圆面积的成员函数
#include<iostream>
using namespace std;
#define PI 3.14159
template<typename T>
class Circle
{
private:
T radius;
public:
Circle(T r);
T area();
};
int main()
{
Circle<int>circle1(10);
cout<<circle1.area()<<endl;
Circle<double>circle2(12.786);
cout<<circle2.area()<<endl;
system("pause");
return 0;
}
template<typename T>
Circle<T>::Circle(T r)
{radius=r;}
template<typename T>
T Circle<T>::area()
{
return PI*radius*radius;
}
public class testleijia
{
public static void main(String args[])
{
long sum =0l;
for (int i = 1; i <= 20; i++)
{
long ji = 1;
for (int j = 1; j <=i; j++)
{
ji *= j;
}
sum += ji;
}
System.out.println("sum is:" + sum);
}
}
#include<iostream>
using namespace std;
int main()
{
int sum=0,sum1,n,i,j;
cout<<"cout the num";
cin>>n;
for(i=1;i<=n;i++)
{
int sum1=1;
for (j=1;j<=i;j++)
{
sum1=sum1*j;
}
sum=sum+sum1;}
cout<<sum;
system("pause");
return 0;
}
class Myclass
{
public int a=0;
值类型和引用类型区别
}
class Test
{
static void Main()
{
f1();
}
static public void f1()
{
int v1=1;
int v2=v1;
v2=2;
Myclass r1=new Myclass();
Myclass r2=r1;
r2.a=2;
}
}