Import Java.util.Scanner;
/**
*
* @author ASUS Chapter 15th example code 1 full Gui 2017.4.9
*
*/
public class Registter {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner input = new Scanner (system.in);
String uname, pwd;
System.out.println ("Please enter user name:");
uname = Input.next ();
System.out.println ("Please enter password:");
PWD = Input.next ();
if (Pwd.length () >= 6) {//Determine password length
SYSTEM.OUT.PRINTLN ("Registered successfully! ");
} else {
SYSTEM.OUT.PRINTLN ("Password length cannot be less than 6 bits!") ");
}
}
}
/**
*
* @author ASUS Chapter 15th example code 2 full Gui 2017.4.9
*
*/
Import Java.util.Scanner;
public class Login {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner input = new Scanner (system.in);
String uname, pwd;
System.out.println ("Please enter user name:");
uname = Input.next ();
System.out.println ("Please enter password:");
PWD = Input.next ();
if (Uname.equals ("TOM") &&pwd.equals ("1234567")) {
SYSTEM.OUT.PRINTLN ("Login Successful! ");
} else {
System.out.println ("User name or password does not match, please login again!");
}
}
}
/**
*
* @author ASUS Chapter 15th example code 3 full Gui 2017.4.9
*
*/
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 ("Two string values are the same.) ");
} else {
System.out.println ("Two string values are not the same.) ");
}
if (str1 = = str2) {
System.out.println ("Two string values are the same.) ");
} else {
System.out.println ("Two string values are not the same.) ");
}
}
}
Import Java.util.Scanner;
/**
*
* @author ASUS Chapter 15th example code 4 full Gui 2017.4.9
*
*/
public class Login4 {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner input = new Scanner (system.in);
String uname, pwd;
System.out.println ("Please enter user name:");
uname = Input.next ();
System.out.println ("Please enter password:");
PWD = Input.next ();
if (Uname.equalsignorecase ("TOM") &&pwd.equalsignorecase ("1234567")) {
SYSTEM.OUT.PRINTLN ("Login Successful! ");
} else {
System.out.println ("User name or password does not match, please login again!");
}
}
}
/**
*
* @author ASUS Chapter 15th example code 5 full Gui 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 Javascore=90;//java Score
Double htmlscore=86.7;//html Results
String scoresheet= "SQL:" +sqlscore+ "\ T" + "java" +javascore+ "\ T" + "HTML" +htmlscore;//Transcript
Print Transcripts
System.out.println ("********** transcript **********");
SYSTEM.OUT.PRINTLN (scoresheet);
}
}
Import Java.util.Scanner;
/**
*
* @author ASUS Chapter 15th example code 6 full Gui 2017.4.9
*
*/
public class Verify {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
declaring variables
Boolean filecorrct=false; Identify the correct file name
Boolean emailcorrect=false; Identify whether e-mail is correct
SYSTEM.OUT.PRINTLN ("---Welcome to the job submission system---");
Scanner input = new Scanner (system.in);
System.out.println ("Please enter Java file name:");
String Filename=input.next ();
System.out.println ("Please enter your e-mail:");
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")) {
Filecorrct=true;
}else{
System.out.println ("File name is invalid. ");
}
Check the format of your mailbox
if (Email.indexof (' @ ')!=-1&&email.indexof ('. ') >email.indexof (' @ ')) {
Filecorrct=true;
}else{
System.out.println ("e-mail is invalid. ");
}
Output test Results
if (FILECORRCT&&FILECORRCT) {
System.out.println ("Job submitted successfully! ");
}else{
System.out.println ("Job submission failed! ");
}
}
/**
*
* @author ASUS Chapter 15th example code 7 full Gui 2017.4.9
*
*/
public class Lyric {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
String words= "Changting outside the ancient road edge of grass green breeze Liudisheng sound remnant Sunset Mountain outside the mountain";
string[] Printword=new String [100];//defines the number of sinks
SYSTEM.OUT.PRINTLN ("* * * Original lyrics format ***\n" +words);
System.out.println ("\n*** lyrics format after splitting");
Printword=words.split ("");//Split by Space
for (int i = 0; i < printword.length; i++) {
System.out.println (Printword[i]);//Print output
}
}
}
/**
*
* @author ASUS Chapter 15th example code 8 full Gui 2017.4.9
*
*/
public class Sbappend {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
StringBuffer sb = new StringBuffer ("Youth Without Regrets");
int num = 110;
Append a string after a string
StringBuffer SB1 = Sb.append ("My Heart Is Eternal");
System.out.println (SB1);
Append a character to a string
StringBuffer SB2 = sb1.append (' ah ');
System.out.println (SB2);
Append an integer number to a string
StringBuffer SB3 = sb2.append (num);
System.out.println (SB3);
}
}
Import Java.util.Scanner;
/**
*
* @author ASUS Chapter 15th example code 9 full Gui 2017.4.9
*
*/
public class Testtnsert {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner input = new Scanner (system.in);
Receive string, stored in an object of type StringBuffer
System.out.println ("Please enter a serial number:");
String Nums=input.next ();
StringBuffer str=new StringBuffer (nums);
Add commas every three bits from the back
for (int i = Str.length ()-3; I >0; i=i-3) {
Str.insert (i, ', ');
}
System.out.println (str);
}
}
Java Chapter 15th Example code