读程序写结果 选拔培训

一、看程序写结果:

1、NOIP 2013 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int a, b;
	cin >> a >> b;
	cout << a << "+" << b << "=" << a + b << endl;
}

输入: 3 5

输出:               

 

2、NOIP 2012 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,ans;
int main()
{	cin>>a>>b>>c;
	d=a+b;
	e=b+c;
	ans=d+e;
	cout<<ans<<endl;
	return 0;	
}

输入:1 2 5

输出:               

 

3、NOIP 2014 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int a, b, c, d, ans;
	cin >> a >> b >> c;
	d = a - b;
	a = d + c;
	ans	= a * b;
	cout << "Ans = " << ans << endl; 
    return(0);
}

输入:2 3 4
输出:Ans =                        

 

#include<bits/stdc++.h>
using namespace std;
int main()
{  
   int x,y,z1,z2;
   x=7;   y=8;
   z1=y-(x++); 
   z2=y-(++x);   
   cout<<"z1="<<z1<<endl<<"z2="<<z2; 
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int i=0, j=0, a=6;
  if ((++i>0)&&(++j>0)) a++;
  printf ("i=%d, j=%d, a=%d\n", i,j,a);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  int  i=0, j=0, k=6;
   if ((++i>0)||(++j>0)) k++;
   printf("%d, %d, %d\n", i, j, k);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int m=5;
  if(m++>5) printf("%d\n",m);
  else printf("%d\n",m--);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{
   char c1,c2,c3;
   c1 = 48;
   c2 = 65;
   c3 = 97;
   cout << c1 << “ “ << c2 << “ “ << c3 << “ “ ;
   cout << int(c1) << “ “ << int(c2) << “ “ << int(c3) << endl;
   return 0;
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int i=111;
  if(i%3==0)  printf("####");
  else printf("****");
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int x, y;
  scanf("%d", &x);
  y=x>12 ? x+10:x-12;
  printf("%d\n", y);
}

输入:12

输出:               

4、NOIP 2015 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main() 
{   int a, b, c; a = 1;
    b = 2;
    c = 3;
    if(a > b)
        if(a > c)  cout << a << ' ';
        else       cout << b << ' '; 
    cout << c << endl;
    return 0;
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  int a=1,b=3,c=5,d=4,x;
   if(a<b)
   if(c<d) x=1;
   else
   if(a<c)
   if(b<d) x=2;
   else x=3;
   else x=6;
   else x=7;
   cout<<x;
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int a=2,b=-1,c=2;
  if(a<b)
  if(b<0) c=0;
  else c++;
  printf("%d\n",c);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  int a=1,b=2,c=3;
    if(a>b)
    a=b;
    b=c;
    c=a;
    printf("a=%d b=%d c=%d\n",a,b,c);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  char i;
   for (; (i=getchar ())!='\n';)
   {switch (i-'a')
     {case 0: putchar (i);
      case 1: putchar (i+1);break;
      case 2: putchar (i+2);  
      case 3: break;
      default:  putchar (i);break;
     }
    }
    printf ("\n");
}

输出:               

5、NOIP 2011 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{   int i,n,m,ans;
    cin>>n>>m;
    i=n;
    ans=0;
    while(i<=m)
	{  ans+=i;
       i++;
    }
    cout<<ans<<endl;
    return 0;
}

输入:10 20

输出:               

 

6、NOIP 2008 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int i, a, b, c, d, f[4];
	for(i = 0; i < 4; i++) cin >> f[i];
	a = f[0] + f[1] + f[2] + f[3];
	a = a / f[0];
	b = f[0] + f[2] + f[3];
	b = b / a;
	c = (b * f[1] + a) / f[2];
	d = f[(b / c ) % 4];
	if(f[(a + b + c + d) % 4] > f[2])
		cout << a + b<< endl;
	else 
		cout << c + d << endl;
	return 0;
}

输入:9 19 29 39

输出:               

 

7、NOIP 2007 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i, p[5], a, b, c, x, y = 20;
	for ( i = 0; i <= 4; i++ )
		scanf( "%d", &p[i] );
	a = (p[0] + p[1]) + (p[2] + p[3] + p[4]) / 7;
	b = p[0] + p[1] / ( (p[2] + p[3]) / p[4]);
	c = p[0] * p[1] / p[2];
	x = a + b - p[(p[3] + 3) % 4];
	if ( x > 10 )
		y += (b * 100 - a) / (p[p[4] % 3] * 5);
	else
		y += 20 + (b * 100 - c) / (p[p[4] % 3] * 5);
	printf( "%d,%d\n", x, y );
	return(0);
}

{注:本例中,给定的输入数据可以避免分母为0或数组元素下表越界。} 输入:6 6 5 5 3

输出:               

 

8、NOIP 2010 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
void swap(int & a, int & b)
{   int t;
    t = a;
    a = b;
    b = t;
}
int main()
{   int a1, a2, a3, x;        
    cin>>a1>>a2>>a3;
    if (a1 > a2)    swap(a1, a2);
    if (a2 > a3)    swap(a2, a3);
    if (a1 > a2)    swap(a1, a2);    
    cin>>x;
    if (x < a2)
	    if (x < a1) cout<<x<<' '<<a1<<' '<<a2<<' '<<a3<<endl;
        else        cout<<a1<<' '<<x<<' '<<a2<<' '<<a3<<endl;
    else
        if (x < a3)   cout<<a1<<' '<<a2<<' '<<x<<' '<<a3<<endl;
        else          cout<<a1<<' '<<a2<<' '<<a3<<' '<<x<<endl;    
    return 0;
}

输入:
91 2 20
77

输出:               

 

10、NOIP 2016 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{   int max, min, sum, count = 0;
    int tmp;
    cin >> tmp;
    if (tmp == 0)  return 0;
    max = min = sum = tmp;
    count++;
    while (tmp != 0)
    {   cin >> tmp;
        if (tmp != 0)
        {   sum += tmp;
            count++;
            if (tmp > max)    max = tmp;
            if (tmp < min)    min = tmp;
        }
    }
    cout << max << "," << min << "," << sum / count << endl;
    return 0;
}

输入: 1 2 3 4 5 6 0 7

输出: _________

 

11、NOIP 2018 普及组初赛18题

#include<bits/stdc++.h>
using namespace std;
char st[100];
int main()
{	scanf("%s", st);
	for (int i = 0; st[i]; ++i)
	   if ('A' <= st[i] && st[i] <= 'Z')	st[i] += 1;	
	printf("%s\n", st);
	return 0;
}

输入:QuanGuoLianSai

输出:_________

 

11、NOIP 2017 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{   int t[256];
    string s;
    int i;
    cin >> s;
    for (i = 0; i < 256; i++)          t[i] = 0;
    for (i = 0; i < s.length(); i++)   t[s[i]]++;
    for (i = 0; i < s.length(); i++)
        if (t[s[i]] == 1)
        {   cout << s[i] << endl;
            return 0;
        }
    cout << "no" << endl;
    return 0;
}

输入:xyzxyw
输出:_________

 

13、NOIP 2019 普及组初赛16题

#include<bits/stdc++.h>
using namespace std;
char st[100];
int main()
{   scanf("%s", st);
    int n = strlen(st);
    for (int i = 1; i <= n; ++i) 
	    if (n % i == 0) 
	    {   char c = st[i - 1];
            if (c >= 'a')   st[i - 1] = c - 'a' + 'A';
        }    
    printf("%s", st);
    return 0;
}

•判断题

1、输入的字符串只能由小写字母或大写字母组成。()
2、若将第8行的“i = 1”改为“i = 0”,程序运行时会发生错误。()
3、若将第8行的“i <= n”改为“i * i <= n”,程序运行结果不会改变。()
4、若输入的字符串全部由大写字母组成,那么输出的字符串就跟输入的字符串一样。()
•选择题
5、若输入的字符串长度为18,那么输入的字符串跟输出的字符串相比,至多有()个字符不同。

6、若输入的字符串长度为(),那么输入的字符串跟输出的字符串相比,至多有36个字符不同。

1、 A. 正确   B. 错误

2、 A. 正确   B. 错误

3、A. 正确   B. 错误

4、A. 正确   B. 错误

5、 A. 18       B. 6                 C. 10       D. 1

6、 A. 36       B. 100000       C. 1         D. 128

 

14、NOIP 2020 普及组初赛16题

#include<bits/stdc++.h>
using namespace std;
char encoder[26] = {'C','S','P',0};
char decoder[26];
string st;
int main()
{ int k = 0;
  for (int i = 0; i < 26; ++i)    if (encoder[i] != 0) ++k;
  for (char x ='A'; x <= 'Z'; ++x)
  { bool flag = true;
    for (int i = 0; i < 26; ++i)
      if (encoder[i] ==x) { flag = false;  break; }
      if (flag) {  encoder[k]= x;   ++k;  }
  }
  for (int i = 0; i < 26; ++i) decoder[encoder[i]- 'A'] = i + 'A';
  cin >> st;
  for (int i = 0; i < st.length( ); ++i)   st[i] = decoder[st[i] -'A'];
  cout << st;
  return 0;
}

判断题

1) 输入的字符串应当只由大写字母组成,否则在访问数组时可能越界。( )
2) 若输入的字符串不是空串,则输入的字符串与输出的字符串一定不一样。()
3) 将第 12 行的“i < 26”改为“i < 16”,程序运行结果不会改变。( )
4) 将第 26 行的"i < 26”改为“i < 16”,程序运行结果不会改变。( )

•单选题

5) 若输出的字符串为“ABCABCABCA”,则下列说法正确的是( )。

6)若输出的字符串为“CSPCSPCSPCSP”,则下列说法正确的是( )。

1. A. 正确   B. 错误

2. A. 正确   B. 错误

3. A. 正确   B. 错误

4 A. 正确   B. 错误

5. A. 输入的字符串中既有S又有P       B. 输入的字符串中既有S又有B      C. 输入的字符串中既有A又有P       D. 输入的字符串中既有A又有B

6. A. 输入的字符串中既有P又有K       B. 输入的字符串中既有J又有R      C. 输入的字符串中既有J又有K        D. 输入的字符串中既有P又有R

 

 

1、NOIP 2007 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
void fun( int *a, int *b )
{    int *k;
    k = a; a = b; b = k;
}
main()
{    int a = 3, b = 6, *x = &a, *y = &b;
    fun( x, y );
    printf( "%d,%d ", a, b );
}

输出:               

 

2、NOIP 2008 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
void foo(int a, int b, int c)
{	if(a > b) 	foo(c, a, b);
	else		cout<<a<<','<<b<<','<<c<<endl;
}
int main()
{	int a, b, c;
	cin >> a >> b >> c;
	foo(a, b, c);
	return 0;
}

输入: 3 1 2

输出:               

 

 

3、NOIP 2009 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int a,b;
int work(int a,int b)
{	if (a%b) return work(b,a%b);
	return b;
}
int main()
{	cin >> a >> b;
	cout << work(a,b) << endl;
	return 0;
}

输入:20 12

输出:               

 

3、NOIP 2009 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int a[3],b[3];
	int i,j,tmp;
	for (i=0;i<3;i++)	cin >> b[i];
	for (i=0;i<3;i++)
	{	a[i]=0;
		for (j=0;j<=i;j++)
		{	a[i]+=b[j];
			b[a[i]%3]+=a[j];
		}
	}
	tmp=1;
	for (i=0;i<3;i++)
	{	a[i]%=10;
		b[i]%=10;
		tmp*=a[i]+b[i];
	}
	cout << tmp << endl;
	return 0;
}

输入:2 3 5

输出:               

 

4、NOIP 2010 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int rSum(int j)
{   int sum = 0;
    while (j != 0)
	{   sum = sum * 10 + (j % 10);
        j = j / 10;
    }
    return sum;
}
int main()
{   int n, m, i;        
    cin>>n>>m;
    for (i = n; i < m; i++)
        if (i == rSum(i))  cout<<i<<' ';
    return 0;
}

输入:90 120

输出:               

 

5、NOIP 2011 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int main()
{   string map= "2223334445556667778889999";
    string tel;
    int i;
    cin>>tel;
    for(i=0;i<tel.length();i++)
       if((tel[i]>='0') && (tel[i]<='9') )          cout<<tel[i];
       else if( (tel[i]>='A') && (tel[i]<='Z'))     cout<<map[tel[i]-'A'];
    cout<<endl;
    return 0;
}

输入:CCF-NOIP-2011

输出:               

 

6、NOIP 2012 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int n,i,ans;
int main()
{	cin>>n;
	ans=0;
	for(i=1;i<=n;i++)	if(n%i==0) ans++;
	cout<<ans<<endl;
	return 0;	
}

输入:18

输出:               

 

7、NOIP 2013 普及组初赛24题

 

输出:               

 

8、NOIP 2014 普及组初赛24题

 

输出:               

 

9、NOIP 2015 普及组初赛24题

 

输出:               

 

10、NOIP 2016 普及组初赛24题

 

输出:               

11、NOIP 2017 普及组初赛24题

 

输出:               

 

12、NOIP 2018 普及组初赛24题

 

输出:               ​​​​​​​

13、NOIP 2019 普及组初赛17题

 

输出:               ​​​​​​​

14、NOIP 2020 普及组初赛17题

 

输出:               ​​​​​​​

1、NOIP 2007 普及组初赛25题

#include<bits/stdc++.h>
using namespace std;
main()
{	int a1[51] = { 0 };
	int i, j, t, t2, n = 50;
	for ( i = 2; i <= sqrt( n ); i++ )
		if ( a1[i] == 0 )
		{	t2 = n / i;
			for ( j = 2; j <= t2; j++ ) a1[i * j] = 1;
		}
	t = 0;
	for ( i = 2; i <= n; i++ )
		if ( a1[i] == 0 )
		{	printf( "%4d", i ); t++;
			if ( t % 10 == 0 )	printf( "\n" );
		}
	printf( "\n" );
}

输出:               

 

1、NOIP 2007 普及组初赛26题

#include<bits/stdc++.h>
using namespace std;
void expand( char s1[], char s2[] )
{	int i, j, a, b, c;
	j = 0;
	for ( i = 0; (c = s1[i]) != '\0'; i++ )
		if ( c == '-' )
		{	a = s1[i - 1]; b = s1[i + 1];
			if ( isalpha( a ) && isalpha( b ) || isdigit( a ) && isdigit( b ) )
/*函数isalpha(a)用于判断字符a是否为字母,isdigit(b) 用于判断字符b是否为数字,如果是,返回1,否则返回0 */
			{   j--;
				do	s2[j++] = a++;
				while ( tolower( a ) < tolower( s1[i + 1] ) );
			}
/*函数tolower(a)的功能是当字符a是大写字母,改为小写,其余情况不变*/
			else s2[j++] = c;
		}else s2[j++] = c;
	s2[j] = '\0';
}
main()
{	char s1[100], s2[300];
	printf( "input s1:" );
	gets( s1 );
	expand( s1, s2 );
	printf( "%s\n", s2 );
}

输入:wer2345d-h454-82qqq

输出:               


 


 

1、NOIP 2008 普及组初赛25题

#include<bits/stdc++.h>
using namespace std;
void func(int ary[], int n )
{	int i=0, j, x;
	j=n-1;
	while(i<j)
	{	while (i<j&&ary[i]>0) i++;
		while (i<j&&ary[j]<0) j--;
		if (i<j)
		{	x=ary[i];
			ary[i++]=ary[j];
			ary[j--]=x;
		}
	}
}
int main()
{	int a[20], i, m;
	m=10;
	for(i=0; i<m; i++)	cin>>a[i];
	func(a, m);
	for (i=0; i<m; i++)		cout<<a[i]<<" ";
	cout<< endl;
	return 0;
}

输入:5 4 -6 -11 6 -59 22 -6 1 10

输出:               

 

1、NOIP 2008 普及组初赛26题

#include<bits/stdc++.h>
using namespace std;
#define MAX 100
void solve(char first[], int spos_f, int epos_f, char mid[], int spos_m, int epos_m)
{	int i, root_m;
	if(spos_f > epos_f)		return;
	for(i = spos_m; i <= epos_m; i++)
		if(first[spos_f] == mid[i])
		{	root_m = i;
			break;
		}
	solve(first, spos_f + 1, spos_f + (root_m - spos_m), mid, spos_m, root_m - 1);
	solve(first, spos_f + (root_m - spos_m) + 1, epos_f, mid, root_m + 1, epos_m);
	cout << first[spos_f];
}
int main()
{	char first[MAX], mid[MAX];
	int len;
	cin >> len;
	cin >> first >> mid;
	solve(first, 0, len - 1, mid , 0, len - 1);	
	cout << endl;
	return 0;
}

输入:
7
ABDCEGF
BDAGECF

输出:               

 

 

 

 

二、完形填空:

1、NOIP 2007 普及组初赛27题

#include<bits/stdc++.h>
using namespace std;
int maxline = 200, kz;
int reverse( char s[] )
{	int i, j, t;
	for ( i = 0, j = strlen( s ) - 1; i < j; 【①】 , 【②】 )
		t = s[i]; s[i] = s[j]; s[j] = t;
	return(0);
}
int main()
{	char line[100];
	cout << "continue? -1 for end." <<endl;
	cin>>kz;
	while(【③】)
	{   cin  >>  line;
		【④】;
		cout << line  <<  endl;
		cout << "continue ? -1 for end." << endl;
		cin >> kz;
	}
}

输出:

1、                                      

2、                                      

3、                                      

4、                                      

 

1、NOIP 2007 普及组初赛28题
(棋盘覆盖问题)在一个2^k\times 2^k2k×2k个方格组成的棋盘中恰有一个方格与其它方格不同(图中标记为-1的方格),称之为特殊方格。现用L型(占3个小方格)纸片覆盖棋盘上除特殊方格的所有部分,各纸片不得重叠,于是,用到的纸片数恰好是(4^k-1)/3(4k−1)/3。在下表给出的一个覆盖方案中,k=2,相同的3各数字构成一个纸片。下面给出的程序使用分治法设计的,将棋盘一分为四,依次处理左上角、右上角、左下角、右下角,递归进行。请将程序补充完整。

#include<bits/stdc++.h>
using namespace std;
int board[65][65], tile; /* tile为纸片编号 */
void chessboard( int tr, int tc, int dr, int dc, int size )/* dr,dc依次为特殊方格的行、列号 */
{	int t, s;
	if ( size == 1 )   ⑤ ;
	t = tile++;
	s = size / 2;
	if ( ⑥ ) chessboard( tr, tc, dr, dc, s );
	else
	{	board[tr + s -1][tc + s -1] = t;
		[⑦];
	}
	if ( dr < tr + s && dc >= tc + s )	chessboard( tr, tc + s, dr, dc, s );
	else
	{	board[tr + s -1][tc + s] = t;
		⑧;
	}
	if ( dr >= tr + s && dc < tc + s )	chessboard( tr + s, tc, dr, dc, s );
	else
	{	board[tr + s][tc + s -1] = t;
		[⑨];
	}
	if ( dr >= tr + s && dc >= tc + s )	chessboard( tr + s, tc + s, dr, dc, s );
	else
	{   board[tr + s][tc + s] = t;
	    [⑩]; 
	}
}
void prtl( int b[][65], int n )
{	int i, j;
	for ( i =1; i <= n; i++ )
	{	for ( j =1; j <= n; j++ ) cout << setw( 3 ) << b[i][j];
		cout << endl;
	}
}
int main()
{	int size, dr, dc;
	cout << "input size(4/8/16/64):" << endl;
	cin >> size;
	cout << "input the position of special block(x,y):" << endl;
	cin >> dr >> dc;
	board[dr][dc] = -1;
	tile++;
	chessboard( 1, 1, dr, dc, size );
	prtl( board, size );
}

输出:

1、                                      

2、                                      

3、                                      

4、                                      

5、                                      

6、                                      

 

1、NOIP 2008 普及组初赛27题

(字符串替换)给定一个字符串S(S仅包含大小写字母),下面的程序将S中的每个字母用规定的字母替换,并输出S经过替换后的结果。程序的输入是两个字符串,第一个字符串是给定的字符串S,第二个字符串S’由26个字母组成,它是a-z的任一排列,大小写不定,S’规定了每个字母对应的替换字母:S’中的第一个字母是字母A和a的替换字母,即S中的A用该字母的大写替换,S中的a用该字母的小写替换;S’中的第二个字母是字母B和b的替换字母,即S中的B用该字母的大写替换,S中的b用该字母的小写替换;…… 以此类推。

#include<bits/stdc++.h>
using namespace std;
char change[26], str[5000];
void CheckChangeRule()
{   int i;
    for (i = 0;i < 26;i ++)
       if ( [    ①     ] )  change[i] -= 'A' - 'a';   
}
void ChangeString()
{   int i;
    for (i = 0;i <strlen(str);i ++)
    {   if (  [   ②   ]  )      str[i] = change[str[i] - 'A'] -'a' + 'A';
        else  [         ③        ]          
    }
}
int main()
{	int i;
    cin >> str ;
    cin >> change;
    CheckChangeRule();
    [              ④            ] 
    cout << str << endl;
    return 0;
}

输出:

1、                                      

2、                                      

3、                                      

4、                                      

 

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
《java程序设计》课程的题库资料,由贺州学院整理,可供学生期末课程复习使用,也可以供相关任课教师出卷使用。 内容示例为: 9. 阅下列程序片段,出运行结果。 public class Test { public static void main(String[] args) { int percent = 10; tripleValue(percent); System.out.println(percent); } public static void tripleValue(int x) { x = 3 * x; } } 代码执行后输出的结果是______。 答案:10 [解析] static 关键字应用的场合有:①用来修饰类中定义的变量,这样的变量称为类变量或静态变量。②可以用来修饰类中定义的方法,这样的方法称为静态方法。③用来修饰初始化语句块,这样的语句块常称为静态初始化语句块。static 在这里表示这个方法为类方法,不属于任何对象实例,而是类所有,描述对象的共有动作,可以用类名直接调用。在调用了tripleValue函数之后,函数的值没有返回,所以percent的值还是10。 10. 阅下列程序片段,出运行结果。 class Shape { public Shape() { System.out.print("Shape"); } } class Circle extends Shape { public Circle() { System.out.print("Circle"); } } public class Test { public static void main(String[] args) { Shape d = new Circle(); } } 代码执行后输出的结果是______。 答案:ShapeCircle [解析] 继承是而向对象编程的一个主要优点之一,它对如何设计Java类有着直接的影响。继承有如下几点好处: ①它可以利用已有的类来创建自己的类,只需要指出自己的类和已有的其他类有什么不同即可,而且还可以动态访问其他有 关类中的信息。 ②通过继承,可以利用Java类库所提供的丰富而有用的类,这些类都已经被很好地实现。 ③当设计很大的程序时,继承可以使程序组织得层次清晰,有利于程序设计相减少错误的发生。该程序首先编了一个Shape的类,然后又编一个类Circle去继承Shape类。由于子类拥有父类所有的属性和方法,所以输出的是ShappeCircle。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值