- 42
- 0
- 约1.22万字
- 约 4页
- 2017-03-26 发布于江苏
- 举报
Java考试参考
1.编写一个类,该类创建的对象可以计算等差数列的和。
代码:
class leisum {
static int qsz,bcz,xs,sum;
leisum(int a,int b,int c){qsz=a; bcz=b; xs=c; }
int sum(){ return sum=xs*qsz+xs*(xs-1)/2*bcz; }}
class example{
public static void main(String args[]){
int sum=0; leisum leisum=new leisum(1,1,100);
sum= leisum.sum();
System.out.println(等差数列的和为:+sum);}}class lader{
double a,b; static double c; double x1,x2; boolean boo;
public lader(double a,double b,double c){
this.a=a; this.b=b; lader.c=c;}
public void getRoots(){ if(a!=0){
System.out.println(一元2次方程:); double d=b*b-4*a*c; if(d=0){x1=(-b+Math.sqrt(d))/(2*a);x2=(-b-Math.sqrt(d))/(2*a); System.out.printf(方程的根:x1=%f,x2=%f\n,x1,x2);}else{ System.out.printf(方程没有实根\n);} }else{ System.out.println(不是一元2次方程);} } }public class liti2_5{
public static void main(String args[ ]){
lader reluctance1=new lader(2,5,1);
lader reluctance2=new lader(3,2,2);
reluctance1.getRoots(); reluctance2.getRoots(); }}
3.编写一个应用程序,用户从键盘输入一行字符串,程序输出该字符串中与模式”[24680]A[13579]{2}”匹配的子字符串。
代码:
import java.util.Scanner;
import java.util.regex.*;
public class one {
public static void main(String[] args){
System.out.println(请输入一行字符串:); Scanner reader=new Scanner(System.in);
String str=reader.nextLine();
Pattern p=Ppile([24680]A[13579]{2});
Matcher m=p.matcher(str);
while(m.find()){ String s=m.group();
System.out.print(从+m.start()+到+m.end()+匹配模式子序列:);System.out.println(s); } } }
4. 编写一个应用程序,将用户从键盘输入的10行文字存入文件。
代码:
import java.io.*;
import java.util.*;
public class one {
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
try{ FileOutputStream
writefile=new FileOutputStream(hello.txt);
int line=1,n=10;
System.out.println(输入+n+行文本,并存入磁盘:);
while(line=n){ String s=reader.nextLine();
byte buffer[]=s.getBytes();
writefile.write(buffer,0,buffer.length); line++; }
writefile.close(); }
catch(IOException e){ System.out.println(Error +e);}
File f=new File(hello.txt);
try{ int i=-1;
RandomAccessFile random=new RandomAccessFile(f,rw);
random.see
您可能关注的文档
- GSMCDMA测试.doc
- gsm关键技术空间分集.doc
- G~G和表面连续性.doc
- GRE最新练习题.doc
- GWPQA便携式电能质量分析仪.doc
- HALCON算子函数ChapterXLD.doc
- HALCON算子函数Chapter:Regions.doc
- GrossCapitalFormation.doc
- HALCON算子函数Chapter:Tools.doc
- handoutforunit.doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
最近下载
- (苏教版)数学五年级上册寒假“天天练”作业设计,含30份题组,附参考答案.doc
- 有限空间作业注意事项.pptx VIP
- 从明代土地产权制度弊端剖析古代土地制度的困境与启示.docx
- 工贸企业常见安全生产隐患诊断检查指导书.pdf VIP
- 麓山景区2006-2020详细规划.doc VIP
- 《地基与基础培训》课件.ppt VIP
- 2026年村卫生室基本公共卫生服务工作计划.docx VIP
- 阿姆斯壮Armstrong--THE BRAIN® DMC80再循环水温控制样本.pdf
- 《地下工程建设疏干排水水资源论证导则》.pdf VIP
- GB 17167-2025用能单位能源计量器具配备和管理通则.pdf
原创力文档

文档评论(0)