Java Chapter 2 sample code and Chapter 2 Sample Code

Source: Internet
Author: User

Java Chapter 2 sample code and Chapter 2 Sample Code

Import java. util. collections;

/**
*
* @ Author asus Chapter 1 sample code 1 full-country group 2017.4.9
*
*/
Public class Registter {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Wrote input = new partition (System. in );
String uname, pwd;
System. out. println ("Enter the User name :");
Uname = input. next ();
System. out. println ("enter the password :");
Pwd = input. next ();
If (pwd. length ()> = 6) {// determine the password length
System. out. println ("registration successful! ");
} Else {
System. out. println ("the password length cannot be less than 6 characters! ");
}
}

}

/**
*
* @ Author asus Chapter 1 sample code 2 full-country group 2017.4.9
*
*/
Import java. util. collections;


Public class Login {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Wrote input = new partition (System. in );
String uname, pwd;
System. out. println ("Enter the User name :");
Uname = input. next ();
System. out. println ("enter the password :");
Pwd = input. next ();
If (uname. equals ("TOM") & pwd. equals ("1234567 ")){
System. out. println ("Logon successful! ");
} Else {
System. out. println ("the user name or password does not match. Please log on again! ");
}
}
}

/**
*
* @ Author asus Chapter 3 sample code 3 full-country group 15th
*
*/
Public class Difference {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
String str1 = new String ("I love my motherland ");
String str2 = new String ("I love my motherland ");
If (str1.equals (str2 )){
System. out. println ("the two strings have the same value. ");
} Else {
System. out. println ("two strings have different values. ");
}
If (str1 = str2 ){
System. out. println ("the two strings have the same value. ");
} Else {
System. out. println ("two strings have different values. ");
}
}
}

Import java. util. collections;

/**
*
* @ Author asus Chapter 4 sample code 4 7.4.9
*
*/
Public class Login4 {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Wrote input = new partition (System. in );
String uname, pwd;
System. out. println ("Enter the User name :");
Uname = input. next ();
System. out. println ("enter the password :");
Pwd = input. next ();
If (uname. inclusignorecase ("TOM") & pwd. inclusignorecase ("1234567 ")){
System. out. println ("Logon successful! ");
} Else {
System. out. println ("the user name or password does not match. Please log on again! ");
}
}
}

/**
*
* @ Author asus Chapter 5 sample code 5 full-country group 2017.4.9
*
*/
Public class PrintScore {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Int sqlScore = 80; // SQL score
Int primary core = 90; // java score
Double htmlScore = 86.7; // HTML score
String scoreSheet = "SQL:" + sqlScore + "\ t" + "java" + javaScore + "\ t" + "HTML" + htmlScore; // transcript
// Print the transcript
System. out. println ("*********** transcript **********");
System. out. println (scoreSheet );
}

}

Import java. util. collections;

/**
*
* @ Author asus Chapter 6 sample code 6 7.4.9
*
*/
Public class Verify {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
// Declare Variables
Boolean fileexpect = false; // identifies whether the file name is correct
Boolean emaiLCorrect = false; // identifies whether email is correct
System. out. println ("--- Welcome To The Job submission System ---");
Wrote input = new partition (System. in );
System. out. println ("Enter the java file name :");
String fileName = input. next ();
System. out. println ("Enter your email address :");
String email = input. next ();
// Check the java file name
Int index = fileName. lastIndexOf ("."); // The location "."
If (index! =-1 & index! = 0 & fileName. substring (index + 1, fileName. length (). equals ("java ")){
Fileexpect = true;
} Else {
System. out. println ("the file name is invalid. ");
}
// Check your email format
If (email. indexOf ('@')! =-1 & email. indexOf ('.')> email. indexOf ('@')){
Fileexpect = true;

} Else {
System. out. println ("E-mail is invalid. ");
}
// Output the detection result
If (fileeffecct & fileeffecct ){
System. out. println ("the job is submitted successfully! ");
} Else {
System. out. println ("Job submission failed! ");
}
}

/**
*
* @ Author asus Chapter 6 sample code 7 full-country group 2017.4.9
*
*/
Public class Lyric {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
String words = "Long pavilion outside the ancient road side grass green sky evening wind help Liu flute residual sunset Mountain ";
String [] printword = new String [100]; // defines the number of recipients.
System. out. println ("*** original lyrics format *** \ n" + words );
System. out. println ("\ n *** format of the split lyrics ***");
Printword = words. split (""); // split by Space
For (int I = 0; I <printword. length; I ++ ){
System. out. println (printword [I]); // print the output
}
}

}

/**
*
* @ Author asus Chapter 8 sample code 8 7.4.9
*
*/
Public class sbAppend {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer ("No regrets ");
Int num = 110;
// Append the string after the string
StringBuffer sb1 = sb. append ("My heart is always ");
System. out. println (sb1 );
// Append a character after the string
StringBuffer sb2 = sb1.append ('Ah ');
System. out. println (sb2 );
// Append an integer to the end of the string
StringBuffer sb3 = sb2.append (num );
System. out. println (sb3 );
}

}

Import java. util. collections;

/**
*
* @ Author asus Chapter 1 sample code 9 Full-country group 2017.4.9
*
*/
Public class TestTnsert {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Wrote input = new partition (System. in );
// Receives strings, which are stored in StringBuffer objects.
System. out. println ("enter a string of numbers :");
String nums = input. next ();
StringBuffer str = new StringBuffer (nums );
// Add a comma every three digits from the back to the back
For (int I = str. length ()-3; I> 0; I = I-3 ){
Str. insert (I ,',');
}
System. out. println (str );
}

}

 

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.