非本专业啊,真写不来,临近交作业
1、编写程序读取一个文本文件的内容,分别统计并显示文件中小写英文字母、大写英文字母及数字字符的个数。
2、定义student类,其中包括4个变量(name,age,gender,score),一个构造方法和show()方法。
name为string类型,用于存储学生姓名;
age为int类型,用于存储学生的年龄;
gender为boolean类型,用于存储学生的性别,男生为false,女生为true;
构造方法包含四个参数,用于为变量赋值;
show()方法无参数,用于输出4个变量的值。
1、编写程序读取一个文本文件的内容,分别统计并显示文件中小写英文字母、大写英文字母及数字字符的个数。
2、定义student类,其中包括4个变量(name,age,gender,score),一个构造方法和show()方法。
name为string类型,用于存储学生姓名;
age为int类型,用于存储学生的年龄;
gender为boolean类型,用于存储学生的性别,男生为false,女生为true;
构造方法包含四个参数,用于为变量赋值;
show()方法无参数,用于输出4个变量的值。
解决方案 »
- 请教java什么 Hasp表存取速度最快?谢谢
- java中的ItemEvent和ActionEvent冲突怎么解决?
- 【SOS】字符集问题
- 有哪位朋友用过j2me Polish?能不能帮帮我,谢谢了~
- 请问ArrayList可以存储简单数据类型吗?
- 请大家帮忙看一下这个错误
- 写一个函数,如何把字符串转换成Map对象
- 在serversock中,接受用字节流接受一个汉字,字节流动长度为3,为何不是2?如何获取正确的长度?
- 高手们,有没有人能解决java 数据报表问题啊!
- method overriding 的意思我明白,但在中文里应该翻译成什么为好?
- 如何获取客户端当前域登录的用户名及密码?
- java JDK安装完成 环境变量设置完成JaVAC依旧无法执行
package t1;
class student{
boolean gender;
String name;
double score;
int age;
public student() {}
public student( boolean gender,String name,
double score,
int age )
{
this.gender=gender;
this.name=name;
this.score=score;
this.age=age;
}
public boolean showgender(){
gender=true;
if (gender==false) {
System.out.println("男");
}else
{System.out.println("女");}
} public String getname(){
return name;}
public double getscore() {
return score;
}
public int getage(){
return age;}
public String toString(){
return this.gender+";"+this.name+";"+this.score+";"+this.age;
}}
class Test{
public static void main(String[] args){
student s=new student(false,"lisi",80,25);
System.out.println(s.toString());
}
}
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);
}
}
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();
}}