资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java大量代码的分段 java大量代码的分段怎么写

java读取txt档分段

//什么意思?能描述清楚你想干什么吗?

成都创新互联公司提供高防主机、云服务器、香港服务器、乐山服务器托管

//切割txt文档?你没说清楚,我就当你是切割文档了!方法挺多的,我就用其中一个好了!

//本方法测试,切割大小为4.5KB的文本文档(皇帝新装),分成5份片段文件!

import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.RandomAccessFile;

public class CutTest {

static File dir=new File("K:\\IO测试\\随机流测试");//目录路径!

public static void main(String[] args) {

File file=new File(dir,"皇帝新装.txt");//文件!

long size=file.length();//文件大小!

//创建随机流!

RandomAccessFile raf1=null,raf2=null;

byte[] bytes=new byte[1024];//缓冲区!

try {

raf1=new RandomAccessFile(file,"r");

for(int i=0,len=0;i=size/1024;i++) {

len=raf1.read(bytes);//读入数据!

raf2=new RandomAccessFile(new File(dir,"片段"+(i+1)+".txt"),"rw");

raf2.write(bytes, 0, len);//写出数据!

raf2.close();//关闭!

}

} catch (FileNotFoundException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}finally {//关流!

if(raf1!=null) {

try {

raf1.close();

} catch (IOException e) {

e.printStackTrace();

}

}

if(raf2!=null) {

try {

raf2.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

}

java分段函数

按照你的要求编写的分段函数的Java程序如下

import java.util.Scanner;

public class Segment {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

double x=sc.nextDouble();

double y;

if(x-5){

y=3*x*x+2*x-1;

}else if(x=-5  x=5){

y=x*Math.sin(x)+Math.pow(2,x);

}else{

y=Math.sqrt(x-5)+Math.log10(x);

}

System.out.println("y="+y);

}

}

运行结果

输入 6

输出 y=1.7781512503836436

求大神指导用Java编程求分段函数(要求用if…else语句实现)

运行结果:

代码如下:

import java.util.Scanner;

public class App65 {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("请输入x值:");

int x = scanner.nextInt();

int y = 0;

if (x  0) {

y = x * x;

} else if (x = 0  x  10) {

y = 2 * x - 1;

} else if (x = 10) {

y = 3 * x - 11;

}

System.out.println("y=" + y);

}

}

Java中如何对list进行分段操作

import java.util.ArrayList;

import java.util.List;

public class listTest {

public static void main(String[] args) {

ListString list = new ArrayListString();

list.add("one");

list.add("two");

list.add("three");

list.add("four");

list.add("five");

list.add("six");

list.add("seven");

intftest = 3;//每次取的数据

intsize = list.size();

inttemp = size / ftest + 1;

boolean special = size % ftest == 0;

ListString cutList = null;

for(int i = 0; i temp; i++) {

if (i == temp - 1) {

if (special) {

break;

}

cutList = list.subList(ftest * i, size);

}else {

cutList = list.subList(ftest * i, ftest* (i + 1));

}

System.out.println("第" + (i + 1) + "组:" + cutList.toString());

}

}

}

得出的结果为:

第1组:[one, two,three]

第2组:[four, five,six]

第3组:[seven]

如果ftest = 1,得出的结果为:

第1组:[one]

第2组:[two]

第3组:[three]

第4组:[four]

第5组:[five]

第6组:[six]

第7组:[seven]


当前名称:java大量代码的分段 java大量代码的分段怎么写
浏览路径:http://cdkjz.cn/article/dohchse.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220