------
資料檔 為
黃千華
123
王宇治
456
楊宇文
789
-------
package chap1;
import java.io.*;
public class test1211 {
public static void main(String args[])throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
int i=0, flag=0,doit=0;
String str,pw;
String name[] = new String [10];
String pass[] = new String [10];
while((str = fr.readLine()) !=null){
name[i]=str;
pass[i]=fr.readLine();
System.out.println("name["+i+"]="+name[i]);
System.out.println("pass["+i+"]="+pass[i]);
i++;
}
while(doit != -1){
System.out.println("請輸入姓名");
str = br.readLine();
System.out.println("請輸入密碼");
pw = br.readLine();
for (int j=0;j<i;j++){
if(str.equals(name[j])&&pw.equals(pass[j]))
flag=1;
}
}
if (flag==1)
System.out.println(str+"包含在資料檔中");
else
System.out.println(str+"不包含在資料檔中");
System.out.println("繼續 請輸入任意鍵,停止-1");
if(Integer.parseInt(br.readLine())==-1)
doit=-1;
flag=0;
}
}
--------------------------------------
package chap1;
import java.io.*;
public class test1211 {
public static void main(String args[])throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader fr = new BufferedReader(new FileReader("data.txt"));
String subjectname[]={"國文","英文","管理學","程式設計","會計學"};
int score[]={85,90,70,85,90};
int credit[]={3,2,3,3,3};
for(int i=0;i<subjectname.length;i++){
System.out.println("科目名稱:"+subjectname[i]+"\t學期成績:"+score[i]+"\t學分數:"+credit[i]);
}
int total = 0;
for(int i=0;i<score.length;i++)
total = total+score[i]*credit[i];
// System.out.println("\n");
System.out.println("total= "+ total);
}
}
留言列表