Java first Knowledge--process Control

Source: Internet
Author: User

1, If/else SELECT statement.

Its grammatical form is:

if (Boolean expression) {

Executes when the Boolean expression is True

}

else{

Executes when the Boolean expression is False

}

2, Do/while Loop statement.

Its grammatical form is:

do {

Statement

} while (Boolean expression);

3, using the above two statements to write a simple bank ATM System Center.

code example:

public static void Main (string[] args) {
System.out.println ("Welcome to China Bank ATM System Center");
Scanner input = new Scanner (system.in);
int count = 0;//user input error password count
String name = "Xiaoming";//Registered user name
String PassWord = "12345678";//user-Set Password
String UserName;//user-entered user name
String UserPassword;//password entered by the user
Double money = 9999,money2,money3;//money is the balance, Money2 is the deposit amount; Money3 is the withdrawal amount;
String str = "";//str Storage user's Choice (y/n)
//Login Interface
do {
count++;
if (count>1&&count<4) {
SYSTEM.OUT.PRINTLN ("Input error, you also have" + (4-count) + "Times login opportunity, press ENTER to continue! ");
}
SYSTEM.OUT.PRINTLN ("Please login");
System.out.print ("User name:");
UserName = input. Next ();
System.out.print ("Password:");
UserPassword = input. Next ();
if (count==3)
Break//Password error over 3 times, loop over
} while (! ( Name.equals (UserName) &&password.equals (UserPassword));
if (count = = 3) {
System.out.println ("Your account has been locked! ");//Login error
}else{//Login successful, enter the service main interface
do{
SYSTEM.OUT.PRINTLN ("Please select service:");
System.out.println ("1, check balance" + "\ T" + "2, withdrawal" + "\ T" + "3, deposit" + "\ T");
int num =input. nextint ();//USER Select service
//service 1, check the balance
if (num = = 1) {
System.out.println ("Your balance is:" +money);
System.out.print ("Y back to main interface, n exit system!") Please select (y/n): ");
str = Input.next ();
}
//Services 2, withdrawals
if (num = = 2) {
System.out.print ("Please enter the withdrawal amount:");
Money2 = input. nextdouble ();
if (Money2 <= money&&money2>0) {
Money = Money-money2;
SYSTEM.OUT.PRINTLN ("Withdrawals are successful! ");
System.out.print ("Y back to main interface, n exit system!") Please select (y/n): ");
str = Input.next ();
}else{
SYSTEM.OUT.PRINTLN ("The amount you have entered is incorrect! ");
System.out.print ("Y back to main interface, n exit system!") Please select (y/n): ");
str = Input.next ();
}
}
//Service 3, deposit
if (num = = 3) {
System.out.print ("Please enter Deposit Amount:");
Money3 = input. nextdouble ();
Money = Money+money3;
System.out.println ("Deposit success! ");
System.out.print ("Y back to main interface, n exit system!") Please select (y/n): ");
str = Input.next ();
}
}
while (Str.equals ("Y") | | Str.equals ("Y"));//Based on user selection, decide whether to return to the main interface
System.out.println ("Welcome next visit!!!");//Exit system
}
}

}

Java primary Knowledge-process Control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.