「units类型java」unit定义

博主:adminadmin 2023-01-27 17:09:07 261

今天给各位分享units类型java的知识,其中也会对unit定义进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

用JAVA编程将任意一个整数转换成中文大写,如101转换为一百零一

import java.io.BufferedReader;

import java.io.FileReader;

public class setrs

{

public static void main(String[] args)

throws Exception

{

String fileName = "c:\\input.txt";

// 单位数组

String[] units = new String[] {"十", "百", "千", "万", "十", "百", "千", "亿"};

// 中文大写数字数组

String[] numeric = new String[] {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};

// 读文件

BufferedReader br = new BufferedReader(new FileReader(fileName));

String temp = null;

temp = br.readLine();

String res = "";

while (null != temp)

{

// 遍历一行中所有数字

for (int k = -1; temp.length() 0; k++)

{

// 解析最后一位

int j = Integer.parseInt(temp.substring(temp.length() - 1, temp.length()));

String rtemp = numeric[j];

// 数值不是0且不是个位 或者是万位或者是亿位 则去取单位

if (j != 0 k != -1 || k % 8 == 3 || k % 8 == 7)

{

rtemp += units[k % 8];

}

// 拼在之前的前面

res = rtemp + res;

// 去除最后一位

temp = temp.substring(0, temp.length() - 1);

}

// 去除后面连续的零零..

while (res.endsWith(numeric[0]))

{

res = res.substring(0, res.lastIndexOf(numeric[0]));

}

// 将零零替换成零

while (res.indexOf(numeric[0] + numeric[0]) != -1)

{

res = res.replaceAll(numeric[0] + numeric[0], numeric[0]);

}

// 将 零+某个单位 这样的窜替换成 该单位 去掉单位前面的零

for (int m = 1; m units.length; m++)

{

res = res.replaceAll(numeric[0] + units[m], units[m]);

}

// 这里打印一下 可以改成写文件

System.out.println(res);

// 读取下一个数

res = "";

temp = br.readLine();

}

}

}

这代码是别人写的希望对你有帮助,祝你学习进步。

用JAVA如何取1831的个位数,十位数,百位数,千位数,的数值

个位数=1831%10

十位数=183%10

百位数=18%10

千位数=1%10

int i;

i = System.in.read(); //实际上要捕获异常

int units,tens,hundreds,thousands;

units = i%10;

tens = (i/10)%10;

hundreads = (i/100)%10;

thousands =(1/1000)%10;

然后再用System.out.print();函数输出结果就好

JAVA如何在运行时编译一个类?

使用jdk1.6提供的JavaCompiler类。使用时一定要保证你的classpath的jre是jdk1.6,不能是纯jre,不然会出问题。

public class test{

String str = "public class test1{static{System.out.println(\"init test1\")}}";

String fileName =

"d:/src/test1.java";//路径随便写

File f = new File(fileName);

FileWriter fw = new FileWriter(f);

fw.write(src);

fw.flush();

fw.close();

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

StandardJavaFileManager fileMgr = compiler.getStandardFileManager(null, null, null);

Iterable units = fileMgr.getJavaFileObjects(fileName);

CompilationTask t = compiler.getTask(null, fileMgr, null, null, null, units);

t.call();

fileMgr.close();

}

java初学者,如何在一个类中使用另一个类并将其作为一个field

你想要声明类型变量是吗:

public class Enrollment {

String date;

Student student;

Unit units[];

public String getDate() {

return date;

}

public Student getStudent() {

return student;

}

public Unit[] getUnits() {

return units;

}

}

units类型java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于unit定义、units类型java的信息别忘了在本站进行查找喔。