62,628
社区成员
发帖
与我相关
我的任务
分享

package test;
public class Student {
private String name;
private int age;
private boolean gender;
private int score;
public Student(String name, int age, boolean gender, int score) {
this.name = name;
this.age = age;
this.gender = gender;
this.score = score;
}
public void show() {
System.out.println("姓名:"+name);
System.out.println("年龄:"+age);
System.out.println("性别:"+(gender?"女":"男"));
System.out.println("成绩:"+score);
}
public static void main(String[] args) {
Student st = new Student("小明",16,false,98);
st.show();
}
}
package test;
import java.io.*;
public class WordCounter {
public static void main(String[] args) throws IOException{
int lowerCount = 0;
int upperCount = 0;
File f = new File("c:/temp/input.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
while(fis.available() > 0) {
char c = (char)fis.read();
if(c >= 'a' && c <= 'z') {
lowerCount ++;
} else if(c >= 'A' && c <= 'Z') {
upperCount ++;
}
}
} catch (FileNotFoundException e) {
System.out.println("指定的文件不存在:"+e.getMessage());
return;
} finally {
if(fis != null) {
fis.close();
}
}
System.out.println("小写字母个数:"+lowerCount);
System.out.println("大写字母个数:"+upperCount);
}
}