The road from my heart to java chapter4
4608 ワード
今日は今までに書いた最も長いプログラムを書きましたが、一つもなく、基本的に今週学んだ知識を網羅しています.100行以上のコードしかありませんが、私は半日もかかりました.深刻で低級な間違いを犯しました.括弧を誤って削除しました.その時、発見しなかったので、修正するのに苦労しました.歯を食いしばってがんばって、この困難期を乗り越えたら、いいです.もう一つ重要なのは、これからプログラムを書くことで自分の効率を高めなければなりません.
ログインシステムを登録し、ログイン後に99乗算表とスコアシステムを表示します.
ログインシステムを登録し、ログイン後に99乗算表とスコアシステムを表示します.
public class TestAll{
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner(System.in);
String[] names = new String[100];
String[] passwords = new String[100];
while(true){
System.out.println(" !");
System.out.println("=============");
System.out.println(" 1. ");
System.out.println(" 2. ");
System.out.println(" 3. ");
System.out.println("=============");
System.out.print(" :");
String num = input.next();
if("1".equals(num)){
while(true){
System.out.print(" :");
String logName = input.next();
System.out.print(" :");
String logPassword = input.next();
boolean bool1 = false;
for(int i = 0; i < names.length; i++){
if(logName.equals(names[i]) && logPassword.equals(passwords[i])){
bool1 = true;
break;
}
}
if(bool1){
System.out.println(" !");
System.out.println(" :");
System.out.println("1. "+"\t");
System.out.println("2. "+"\t");
String num1 = input.next();
if("1".equals(num1)){
for(int i = 1; i <= 9; i++){
for(int j = 1; j <= i; j++){
System.out.print(i+"*"+j+"="+(i*j)+"\t");
}
System.out.println();
}
}else if("2".equals(num1)){
String[] studentnames = new String[3];
double[] studentscores = new double[3];
double allscores = 0;
double avg = 0;
for(int i = 0; i < studentnames.length; i++){
System.out.print(" :");
String snames = input.next();
System.out.print(" :");
double sscores = input.nextDouble();
if(studentnames[i] == null){
studentnames[i] = snames;
studentscores[i] = sscores;
}
}
for(int i = 0; i < studentscores.length-1; i++){
for(int j = 0; j < studentscores.length-1-i; j++){
if(studentscores[j] < studentscores[j+1]){
double item = studentscores[j];
studentscores[j] = studentscores[j+1];
studentscores[j+1] = item;
String str = studentnames[j];
studentnames[j] = studentnames[j+1];
studentnames[j+1] = str;
}
}
}
for(int i = 0; i < studentscores.length; i++){
System.out.println(studentnames[i]+" "+studentscores[i]+"\t");
}
for(int i = 0; i < studentscores.length; i++){
allscores += studentscores[i];
//avg = allscores / 3;
//System.out.println(" :"+avg);
}
avg = allscores / 3;
System.out.println(" :"+avg);
//for(int i = 0; i < studentscores.length; )
}
break;
}else{
System.out.println(" !");
System.out.print(" ( / ):");
String str = input.next();
if(" ".equals(str)){
break;
}else if(" ".equals(str)){
System.out.println(" !");
}else{
System.out.println(" !");
}
}
}
}else if("2".equals(num)){
System.out.println(" !");
while(true){
System.out.print(" :");
String regName = input.next();
boolean bool2 = true;
for(String item : names){
if(regName.equals(item)){
System.out.println(" , !");
bool2 = false;
break;
}
}
if (bool2){
System.out.print(" :");
String regPassword = input.next();
System.out.println(" !");
for(int i = 0; i < names.length; i++){
if(names[i] == null){
names[i] = regName;
passwords[i] = regPassword;
break;
}
}
break;
}
}
}else if("3".equals(num)){
System.out.println(" !");
}else{
System.out.println(" !");
}
}
}
}