}catch (Exception e){
e.printStackTrace();
}finally {
if (writer!= null){
writer.close();
}
}
}
}
第二题:
public class Read {
public static void main(String[] args) throws Exception {
readFile("D://test.txt");
}
public static void readFile(String fileName ) throws Exception {
BufferedReader isr = new BufferedReader(new FileReader(fileName));
String str = null;
int allnumber =1;
str = isr.readLine();
String [] strings = str.split("\\s+");
float [] sum ={Float.valueOf(strings[0]),Float.valueOf(strings[1]),Float.valueOf(strings[2])};
float [] min ={Float.valueOf(strings[0]),Float.valueOf(strings[1]),Float.valueOf(strings[2])};
float [] max ={Float.valueOf(strings[0]),Float.valueOf(strings[1]),Float.valueOf(strings[2])};
System.out.println(str);
while ((str = isr.readLine())!= null){
System.out.println(str);
deal(str,sum,min,max);
allnumber++;
}
if (isr!= null){
isr.close();
}
System.out.println("三门课最大值:"+max[0]+"\t"+max[1]+"\t"+max[2]);
System.out.println("三门课最小值:"+min[0]+"\t"+min[1]+"\t"+min[2]);
System.out.println("三门课平均值:"+sum[0]/allnumber+"\t"+sum[1]/allnumber+"\t"+sum[2]/allnumber);
}
public static void deal(String str, float[] sum, float[] min, float[] max){
String [] strings = str.split("\\s+");
for (int i=0;i3;i++) {
sum[i] = sum[i] + Float.valueOf(strings[i]);
if (max[i]Float.valueOf(strings[i])) {
max[i] = Float.valueOf(strings[i]);
}
if (min[i]Float.valueOf(strings[i])) {
min[i] = Float.valueOf(strings[i]);
}
}
}
}
Java编写程序,输出英文字母A~Z及其对应的Unicode编码值!!!急急急~~~public class AlphabetToUnicode{
public static void main(String[] args) {
String uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String Lowercase = "abcdefghijklmnopqrstuvwxyz";
System.out.println(stringToUnicode(uppercase));
System.out.println(stringToUnicode(Lowercase));
}
public static String stringToUnicode(String s) {
String str = "";
for (int i = 0; is.length(); i++) {
int ch = (int) s.charAt(i);
if (ch255)
str += s.charAt(i) + ": " + "\\u" + Integer.toHexString(ch) + "\n";
else
str += s.charAt(i) + ": " + "\\u00" + Integer.toHexString(ch) + "\n";
}
return str;
}
}
Java 编写英文单词的汉语翻译public static void main(String[] args) throws Exception {
MapString, String map = geDictionary();
String str = "love";
if (map.containsKey(str)) {
System.out.println(map.get(str));
} else {
System.out.println("词库里没有这个词");
}
}
public static MapString, String geDictionary() {
MapString, String map = new HashMapString, String();
map.put("dictionary", "字典");
map.put("map", "地图");
map.put("love", "爱");
map.put("cat", "猫");
map.put("dog", "狗");
map.put("bird", "鸟");
return map;
}
这几个小程序用完整的JAVA语言如何编写3:编写一个方法统计一个字符在某字符串中java编程代码中英对照的出现次数java编程代码中英对照; public class Test03{
public int getCounts(String s,char c){
char[] cc = s.toCharArray();
int size = cc.length;
int counts = 0;
for(int i=0;isize;i++){
if(cc[i]==c)counts++;
}
return counts;
}
public static void main(String[] args){
Test03 t = new Test03();
String s = "hello! java. I love you.";
char c = 'o';
System.out.println("字符串s: "+s);
System.out.println("字符c: "+c);
System.out.println("c在s中出现java编程代码中英对照的个数: "+t.getCounts(s,c));
}
推荐阅读
- 虚拟机怎么放大图标,虚拟机怎么放大桌面
- 千万数据统计oracle,千万数据统计条数优化
- 网易开发的游戏幽灵游戏,网易开发的新游戏
- 大班游戏课角色扮演,大班游戏课角色扮演教案
- vb.netdimd%的简单介绍
- 隐藏wordpress后台登陆,wordpress平台隐私性怎么样
- erp系统上的单位计量换算,erp数量
- php筛选数据库 php商品筛选
- wordpresswap插件,wordpress插件开发视频教程