C # object-oriented programming exercises,
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace ConsoleApplication1 {class Program {public class apple {public string info; public apple () {} public string app (string [] a) {foreach (string value in) info + = value + "+"; info = info. substring (0, info. length-1); return info ;}
Python core programming-exercises-Chapter 2, Chapter 2
PS: PDF online address: http://bcmi.sjtu.edu.cn /~ Zhaohai/ptm2012/data/Python-kernel.programming.v2.pdf
2-1 variables, print and string formatting operators. Start the interactive interpreter, assign values (strings, values, and so on) to some variables, and display their values by entering the variable names. Use the print statement to do the same thi
7-9. Translation(a) writing a character translation program (functionally similar to the TR command in Unix). We call this function tr (), which hasThree string parameters: source string, Destination string, basic string, syntax is defined as follows:def tr (Srcstr, DSTSTR, String)The content of Srcstr is the character set that you intend to "translate", Dsrstr is the character set that is obtained after translation, and string isThe string to which you intend to perform the translation operatio
);intMain () {using namespacestd; DoubleLight_years; cout"Enter the number of light years:"; CIN>>Light_years; Cin.Get(); cout"Light years =""Astronomical Units"; Cin.Get();}DoubleConvertDoublelight_years) { DoubleUnits = Light_years *63240; returnunits;}2.7.7#include voidTimerint,int);intMain () {using namespacestd; inthours, minutes; cout"Enter the number of hours:"; CIN>>hours; cout"Enter the number of minutes:"; CIN>>minutes; Cin.Get(); Timer (hours, minutes); Cin.Get();}voidTimerintHo
#include using namespacestd;intMain () {intA,b,c; cout"Please enter a number of three integer types:"Endl; CIN>>a>>b>>C; voidSortintXintYintz); Sort (a,b,c);//ABC has a specific value, called the actual parameter return 0;} voidSortintXintYintZ//used to receive actual parameters, called formal parameters{ inttemp; if(x>y) {temp=x;x=y;y=temp; } if(zx) cout','','Endl; Else if(z','','Endl; Elsecout','','Endl;}Rectification C + + programming Chap
#include using namespacestd;intMain () {intA,b,c; intFintXintYintZ);//this is the declaration of the function//CIN Sonsole Consolecout"Please enter a number of three integer types:"Endl; CIN>>a>>b>>B; C=f (A,B,C);//ABC has a specific value, called the actual parametercoutEndl; return 0;}intFintXintYintZ//used to receive actual parameters, called formal parameters{ intm; if(xy) M=x; Elsem=y; if(zm) m=Z; return(m);}Rectification C + + programming Cha
Lwtviewcontroller.m////LWTVIEWCONTROLLER.M//Network Programming Exercises--Post-json data////Created by Apple on 14-7-2.//Copyright (c) 2014 LWT. All rights reserved.//#import "LWTViewController.h"@interfaceLwtviewcontroller ()@end@implementationLwtviewcontroller- (void) viewdidload{[Super Viewdidload]; //additional setup after loading the view, typically from a nib.}- (void) Touchesbegan: (Nsset *) touches
Exercise 5_2.py#!/usr/bin/pythondef mymultiple (x, y): return x * y for I in range (1, ten): for J in range (1, i + 1): print '%d *%d =%2d '% (j, I, Mymultiple (i, J)), if j = = I:printExercise 5_3.py#!/usr/bin/env pythoninputscore = Int (raw_input (' Input a Integer: ')) if Inputscore >= 90:print ' Your score is a (90 ~100) ' elif inputscore >= 80:print ' Your score are B (80~89) ' elif inputscore >= 70:print ' Your score is C (70~ () ' Elif inputscore >= 60:print ' Your score is D (60~69) ' El
reference type, when he is directly assigned to the value of the corresponding reference position is assigned to the string variable, so, two times the result is true. If you assign a value with the new String (), the result will be different.
Write a program that simulates the result of tossing a coinPackage Net.mindview.operators;import Java.util.random;importStaticnet.mindview.util.print.*; Public classThrowcron { Public Static voidMain (string[] args) {Random num=NewRandom (); intA = Num.
# -*- coding:utf-8 -*-#strip正则表达式#if 只字符串,不带参数,去首尾空白#else 去除参数text=input("Input a text:")import redef st(text): #原样返回检测 textReg=re.compile(r"^\w+$") #前后或前或后,空白检测 blankReg=re.compile(r‘^\s+(\w+)\s+$|^\s+(\w+)|(\w+)\s+$‘) check_blank=blankReg.search(text) #参数检测 argsReg=re.compile(r‘(\w+)\s+\.*‘) check_args=argsReg.search(text) if textReg.search(text): return(text) elif check_blank: #groups检测,直接通过groups输出 for i in check_blank.groups(): if i: return(i) elif check_args: return(check_args.group(1)) el
# -*- coding:utf-8 -*-# 7.18.1# 强口令检测# 写一个函数,使用正则表达式,确保传入的口令字符串是强口令# 长度不少于8个字符,同时包含大小写,至少有1个数字import repassd=input("Input your password:")ch_len=re.compile(r‘.{8,}‘)ch_uppercase=re.compile(r‘[A-Z]{1,}‘)ch_case=re.compile(r‘[a-z]{1,}‘)ch_number=re.compile(r‘\d{1,}‘)if ch_len.search(passd): if not ch_case.search(passd) or not ch_uppercase.search(passd) or not ch_number.search(passd) : print("弱密码") else: print("strong enough")else: print("length less then 8")"Python
#!python3# -*- coding:utf-8 -*-# 8.9.3#打开指定路径中所有.txt文件#用户输入正则,将匹配行输出,输出文件名import re,ospat=input("输入要处理的文件夹绝对路径:")lis_dir=os.listdir(pat)lis_txt=[]for x in lis_dir: #取出.txt结尾的文件名,加进列表 if re.search(r‘\.txt$‘,x): lis_txt.append(x)text=input("输入你的自定义正则表达式:")regCom=re.compile(text)#regCom=re.compile(‘.*name.*‘)#循环处理文件for fi in lis_txt: fi=os.path.join(pat,fi) fi_open=open(fi) for fi_line in fi_open.readlines(): fi_reg=regCom.search(fi_line) if fi_reg: print(fi_reg.group()) fi_open.close()print("查找完成"
Create a class that contains an int field and a char field that are not initialized and print them out to verify that Java performs the default initialization.public class Domtest{int I;char c;public domtest () {System.out.println ("i=" +i+ "\nc=[" +c+ "]" + "\ n []");/** * Print result as follows I =0 c=[] []//only for comparison reference */}/** * @param args */public static void main (string[] args) {new domtest ();}}Java Programming Ideas (Fourt
numbers, ranging from large to small. (b) is the same as a, but it is arranged in a dictionary order from large to small. " # (a) Defget_num (): globalnum_listnum_list= []num= ' whilenum!= '! ': num=raw_input (' Enter some numbers to '! "End"). Strip () ifnum!= '! ': try: num=float (num) except: print ' input is wrong, please re-enter ' get_num () else: num_list.append (num) else: breakreturnnum_listdefsort_descending (): get_num () printsorted (num_list,reverse=true) print '---------------
Third questionPackage net.mindview.interfaces;Abstract classbase{ PublicBase () {print (); } Abstract voidprint ();} Public classTest3 extends base{Private inti =5; @Overridevoidprint () {System. out. println (i); } Public Static voidMain (string[] args) {Test3 T=NewTest3 (); T.print (); }}Output Result:0 5When calling the base class construction method, it simply allocates a chunk of memory space to the member variable of the subclass and sets the value of the memory space to the defa
! " Break Else : Pass2-11#!/usr/etc/env python#-*-coding:utf-8-*-MyList =[]i=0sum=0 whileI: Counter=input ("Please enter the number:\n") MyList+=[counter] I+=1 whileTrue:Print"""(1) Take Five numbers and (2) Take five numbers of the average (3) Exit"""Choose=input ("Please enter your choose:\n") ifChoose==1: forJinchRange (len (myList)): Sum+=Mylist[j]Printsumelifchoose==2: forJinchRange (len (myList)): Sum+=Mylist[j]P
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.