JavaScript(1)

JavaScript简介:JavaScript是web的编程语言,所有现代的HTML页面都使用JavaScript。JavaScript是一种轻量级的编程语言;可以插入HTML页面的编程代码;可由所有的现代浏览器执行。 1、javascript显示数据javascript可以通过不同的方式来输出数据:使用 window.alert() 弹出警告框。使用 document.write() 方法将内容写到HTML文档中。使用 innerHTML 写入到HTML元素。使用 console.log() 写入到浏览器的控制台2、javascript语法数字(number)字面量,可以是整数或者是小数,或者科学计数(e)。字符串(string)字面量,可以使用单引号或者双引号。表达式字面量,用于计算。数组(array)字面量,定义一个数组:[10,20,30,40]对象(object)字面量,定义一个对象:{name:"zhangsan",age:22,sex:"men"}函数(function)字面量,定义...
ymnets ymnets·2020-03-25

爬虫入门【9】Python链接Excel操作详解-openpyxl库

Openpyx是一个用于读写Excel2010各种xlsx/xlsm/xltx/xltm文件的python库。现在大多数用的都是office2010了,如果之前之前版本的可以使用xlrd读,xlwt写,这里就不介绍了。fromopenpyxlimportWorkbookwb=Workbook()#创建一个工作簿ws=wb.active#获取工作的激活工作表ws['A1']=42#在A1中插入内容ws.append([1,2,3])#这里其实是在第二行插入了3个数字,占用了三个单元格importdatetimews['A2']=datetime.datetime.now()#在A2中插入了当前时间,把上一句的那个1挤掉了wb.save('sample.xlsx')#保存到当前目录创建一个workbook一般创建workbook后至少会有一个worksheet,我们可以通过active属性来获取。我们还可以通过create_sheet()方法来创建新的worksheet。一般默认创建的sheet的名字是序列化的,我们可以更改title属性来设置想要的名称。一旦我们指定了名称,可以使用key...

C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式

前言作为项目管理大队中的一员,在公司里面接触最多的就是Excel文件了,所以一开始就想从Excel入手,学习简单的二次开发,开始自己的编程之路!程序界面功能说明打开文件按钮,可以由使用者指定要操作的Excel文件,并在后面的textBox中显示出文件路径。设置单元格按钮,可以根据程序设置Excel文件的内容。退出程序按钮,关闭窗体。程序源代码1usingSystem;2usingSystem.Collections.Generic;3usingSystem.ComponentModel;4usingSystem.Data;5usingSystem.Drawing;6usingSystem.Linq;7usingSystem.Text;8usingSystem.Windows.Forms;9usingSystem.Reflection;10usingMicrosoft.Office.Interop.Excel;11namespaceExcelReadAndWrite12{13publicpartialclassForm1:Form14{15publicStringfilename=str...

Java 在指定目录建立指定文件名的文件 并输入内容

1packagerunoob;2importjava.io.File;3importjava.io.FileInputStream;4importjava.io.FileOutputStream;5importjava.io.IOException;6importjava.io.InputStreamReader;7importjava.io.OutputStreamWriter;89publicclassFileDemo{1011publicstaticvoidmain(String[]args)throwsIOException{12//TODOAuto-generatedmethodstub13Stringseparator=File.separator;14Stringdir="temp01"+separator+"temp02";15StringfileName="hello.txt";16Filefile=newFile(dir,fileName);17if(file.exists()){18System.out.println(file.getAbsolutePath()...

Java 设计一个贷款计算器 简易

1importjavax.swing.*;2importjava.awt.*;3importjava.awt.event.*;4importjavax.swing.border.*;56publicclassLoanCalculatorextendsJFrame{7privateclassButtonListenerimplementsActionListener{8@Override9publicvoidactionPerformed(ActionEvente){10//TODOAuto-generatedmethodstub11doubleinterest=12Double.parseDouble(jtfAnnualInterestRate.getText());13intyear=14Integer.parseInt(jtfNumberOfYears.getText());15doubleloanAmount=16Double.parseDouble(jtfLoanAmount.getText());1718doublemonthlyInterest=interest/1200;...

Java 内部类和匿名类 实现JButton动作 ActionListener类

1importjavax.swing.*;2importjava.awt.*;3importjava.awt.event.*;45publicclassControlCircle2extendsJFrame{6privateJButtonjbtEnlarge=newJButton("Enlarge");7privateJButtonjbtShrink=newJButton("Shrink");8privateCirclePanelcanvas=newCirclePanel();910publicControlCircle2(){11JPanelpanel=newJPanel();12panel.add(jbtEnlarge);13panel.add(jbtShrink);14this.add(canvas,BorderLayout.CENTER);15this.add(panel,BorderLayout.SOUTH);1617jbtEnlarge.addActionListener(newEnlargeListener());18jbtShrink.addActionListener...

Java 有理数类 分数类 Rational类的设计与实现

实现Rational类的加减乘除,要实现其可比较性,要覆盖toString()方法,要实现不同数据类型的转换等。1packagechapter14;23publicclassRationalextendsNumberimplementsComparable{4privatelongnumerator=0;5privatelongdenominator=1;67publicRational(){8this(0,1);9}10publicRational(longnumerator,longdenominator){11//TODOAuto-generatedconstructorstub12longgcd=gcd(numerator,denominator);13this.numerator=((denominator>0)?1:-1)*numerator/gcd;14this.denominator=Math.abs(denominator)/gcd;15}1617privatestaticlonggcd(longn,longd){18//TODOAuto-generatedm...

Java ArrayList的使用方法

首先ArrayList的一个简单实例:1packagechapter11;2importjava.util.ArrayList;34publicclassTestArrayList{56publicstaticvoidmain(String[]args){7//TODOAuto-generatedmethodstub8ArrayList<String>cityList=newArrayList<String>();9cityList.add("London");10cityList.add("Denver");11cityList.add("Paris");12cityList.add("Miami");13cityList.add("Seoul");14cityList.add("Tokyo");1516System.out.println("Listsizeis"+cityList.size()+17"IsMiamiinthelist?"+cityList.contains("Miami")+18"ThelocationofDenverinthelist?"...

Java Super 覆盖方法

子类从父类中继承方法,有时候,子类需要修改父类中定义的方法的实现,这称作方法覆盖。比如,GeometricObject类中的toString方法返回表示集合对象的字符串,这个方法就可以被覆盖,返回表示圆的字符串。 1publicStringtoString(){2  returnsuper.toString()+"radiusis"+radius;3} 要在Circle类中调用定义在GeometricObject中的toString方法,使用super.toString()。需要注意的是:1、仅当实例方法是可访问时,它才能被覆盖。因为私有方法不能在它的类之外被访问。如果子类中定义的方法在父类中是私有的,那么这两个类完全没有关系。2、静态方法能被继承,但是不能被覆盖。如果父类中定义的静态方法在子类中被重新定义,那么定义在父类中的静态方法将被隐藏,使用父类名.静态方法名调用隐藏的静态方法。 另外,说一下Object类中equals的方法的默认实现和覆盖方法: 1publicbooleanequals(Objectobj){2return(this==...

Java 父类和子类

1packagechapter11;23publicclassGeometricObject1{4privateStringcolor="white";5privatebooleanfilled;6privatejava.util.DatedateCreated;78publicGeometricObject1(){9dateCreated=newjava.util.Date();10}1112publicGeometricObject1(Stringcolor,booleanfilled){13dateCreated=newjava.util.Date();14this.color=color;15this.filled=filled;16}1718publicStringgetColor(){19returncolor;20}21publicvoidsetColor(Stringcolor){22this.color=color;23}2425publicbooleanisFilled(){26returnfilled;27}28publicvoidsetFilled(boolea...
ymnets ymnets·2020-03-25

Java 使用对话框选择文件并输出到控制台

importjava.util.*;importjava.io.*;importjavax.swing.JFileChooser;publicclassReadFileUsingJFileChooser{/***@paramargs*@throwsException*/publicstaticvoidmain(String[]args)throwsException{//TODOAuto-generatedmethodstubJFileChooserjfc=newJFileChooser();if(jfc.showOpenDialog(null)==JFileChooser.APPROVE_OPTION){Filefile=jfc.getSelectedFile();Scannerinput=newScanner(file);while(input.hasNext()){System.out.println(input.nextLine());}input.close();}elseSystem.out.println("Nofileisselected!");}} 总结:1...

Java 数组 可变长参数 实例

可以把类型相同但个数可变的参数传递给方法,方法中的参数声明如下:typeName...parameterName(类型名...参数名)在方法声明中,指定类型后紧跟着省略号...,只能给方法指定一个可变长参数。Java将可变长参数当成数组对待。可以将一个数组或可变的参数个数传递给可变长参数。当用可变的参数个数调用方法时,Java会创建一个数组并把参数传给它。1packagefiveChapter;23publicclassVarArgsDemo{45/**6*@paramargs7*/8publicstaticvoidmain(String[]args){9//TODOAuto-generatedmethodstub10printMax(34,3,3,2,26.5,122);11printMax(newdouble[]{1,2,3,4});12}1314publicstaticvoidprintMax(double...numbers){15if(numbers.length==0){16System.out.println("Noargumentpassed");17return;18...

Java 返回一个整数的各个数字之和的一种方法

publicstaticlongsumDigits(longn){longtotal=0;longnumber=n;while(number!=0){total=total+number%10;number=(number-number%10)/10;}returntotal;}publicstaticvoidtestSumDigits(){System.out.println("Enteralonginteger:");Scannerinput=newScanner(System.in);longn=input.nextLong();longresult=sumDigits(n);System.out.print("Thesumofeverynumberoftheintegeris:"+result);} ...

JAVA 打印指定月份日历

1packagelearnExercise;23importjava.util.Scanner;45publicclassPrintCalender{67/**8*@paramargs9*/10publicstaticvoidmain(String[]args){11//TODOAuto-generatedmethodstub12Scannerinput=newScanner(System.in);1314System.out.print("Enterfullyear(e.g.,2001):");15intyear=input.nextInt();1617System.out.print("Entermonthasnumberbetween1and12:");18intmonth=input.nextInt();1920printMonth(year,month);2122}2324privatestaticvoidprintMonth(intyear,intmonth){25//TODOAuto-generatedmethodstub26printMonthTitle(year,mo...

Java中生成随机字符的方法总结

packagelearnExercise;publicclassRandomCharacter{publicstaticchargetRandomCharacter(charch1,charch2){return(char)(ch1+Math.random()*(ch2-ch1+1));//因为random<1.0,所以需要+1,才能取到ch2}publicstaticchargetRandomLowerCaseLetter(){returngetRandomCharacter('a','z');}publicstaticchargetRandomUpperCaseLetter(){returngetRandomCharacter('A','Z');}publicstaticchargetRandomDigitLetter(){returngetRandomCharacter('0','9');}publicstaticchargetRandomCharacter(){returngetRandomCharacter('u0000','uFFFF');}}上面记录的是生成不同区间...
首页上一页...624625626627628下一页尾页