[英]How can I make the sign out option to not appear even though I already pressed 1 to sign in (do while loop Java)
您好,我目前是 Java 新手,我想知道如何使退出選項消失,因為我已經輸入了登錄選項。TL;DR 即使我已經按下 1 進行簽名,退出選項仍然出現in.我還需要幫助制定扣除和工資系統這是我的代碼:
import java.io.*;
public class Security{
public static void main(String[] args)
{
BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));
int sign=0;
int hour=0;
int minute=0;
int out=0;
int hour2=0;
int minute2=0;
int pre=0;
int late=0;
int deduction=0;
String Str_1;
String Str_2;
String Str_3;
String Str_4;
String Str_5;
String Str_6;
String Str_7;
try{
System.out.println("Press 1 to sign in ");
Str_1=dataIn.readLine();
sign=Integer.parseInt(Str_1);
System.out.println("Press 2 to sign out ");
Str_5=dataIn.readLine();
sign=Integer.parseInt(Str_5);
if(late>=3)
{
System.out.println("Your Salary has been deducted");
deduction=pre-50;
}
do{
System.out.println("Everytime you sign in you get a 50$ salary");
System.out.println("Enter your name: ");
Str_2=dataIn.readLine();
System.out.println("Enter Hour: ");
Str_3=dataIn.readLine();
hour=Integer.parseInt(Str_3);
System.out.println("Enter Minute: ");
Str_4=dataIn.readLine();
minute=Integer.parseInt(Str_4);
do{
System.out.println("Number of lates: "+late);
late++;
}while(hour>7||minute>30);
if(hour<=7&&minute<=30)
{
System.out.println("You are on time!");
}
else if(hour>7||minute>30)
{
System.out.println("You are late!");
}
System.out.println("Press 1 to sign in ");
Str_1=dataIn.readLine();
sign=Integer.parseInt(Str_1);
System.out.println("Press 2 to sign out ");
Str_5=dataIn.readLine();
sign=Integer.parseInt(Str_5);
}while(sign==1);
while(sign==2)
{
System.out.println("Enter Your Name: ");
Str_5=dataIn.readLine();
System.out.println("Enter Hour: ");
Str_6=dataIn.readLine();
hour2=Integer.parseInt(Str_6);
System.out.println("Enter Minute: ");
Str_7=dataIn.readLine();
minute2=Integer.parseInt(Str_7);
System.out.println("Thank you for working hard!");
System.out.println("Here's your salary!");
pre=0+50;
}
System.out.println("Press 1 to sign in ");
Str_1=dataIn.readLine();
sign=Integer.parseInt(Str_1);
System.out.println("Press 2 to sign out ");
Str_5=dataIn.readLine();
sign=Integer.parseInt(Str_5);
}
catch(Exception e)
{
System.out.println("Oops you entered something wrong");
}
}
}
System.out.println("Press 1 to sign in , Press 2 to sign out ");
Str_1=dataIn.readLine();
sign=Integer.parseInt(Str_1);
if(sign==2)
Str_5=Str_1;//i write here because maybe u need str_5
但是你為什么要使用 str_1,2,3,4,5 ...
sign = Integer.parseInt(in.readLine());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.