java第15章範例程式碼

來源:互聯網
上載者:User

標籤:格式   system   length   輸出   word   mail   enter   out   --   

import java.util.Scanner;

/**
*
* @author asus第15章範例程式碼1 全桂群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("請輸入使用者名稱:");
uname = input.next();
System.out.println("請輸入密碼:");
pwd = input.next();
if (pwd.length() >= 6) {// 判斷密碼長度
System.out.println("註冊成功!");
} else {
System.out.println("密碼長度不能小於6位!");
}
}

}

/**
*
* @author asus第15章範例程式碼2 全桂群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("請輸入使用者名稱:");
uname = input.next();
System.out.println("請輸入密碼:");
pwd = input.next();
if (uname.equals("TOM")&&pwd.equals("1234567")) {
System.out.println("登入成功!");
} else {
System.out.println("使用者名稱或密碼不匹配,請重新登入!");
}
}
}

/**
*
* @author asus第15章範例程式碼3 全桂群2017.4.9
*
*/
public class Difference {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1 = new String("我愛我的祖國");
String str2 = new String("我愛我的祖國");
if (str1.equals(str2)) {
System.out.println("兩個字串值相同。");
} else {
System.out.println("兩個字串值不相同。");
}
if (str1 == str2) {
System.out.println("兩個字串值相同。");
} else {
System.out.println("兩個字串值不相同。");
}
}
}

import java.util.Scanner;

/**
*
* @author asus第15章範例程式碼4 全桂群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("請輸入使用者名稱:");
uname = input.next();
System.out.println("請輸入密碼:");
pwd = input.next();
if (uname.equalsIgnoreCase("TOM")&&pwd.equalsIgnoreCase("1234567")) {
System.out.println("登入成功!");
} else {
System.out.println("使用者名稱或密碼不匹配,請重新登入!");
}
}
}

/**
*
* @author asus第15章範例程式碼5 全桂群2017.4.9
*
*/
public class PrintScore {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int sqlScore=80; //SQL成績
int javaScore=90;//java成績
double htmlScore=86.7;//HTML成績
String scoreSheet="SQL:"+sqlScore+"\t"+"java"+javaScore+"\t"+"HTML"+htmlScore;//成績單
//列印成績單
System.out.println("**********成績單**********");
System.out.println(scoreSheet);
}

}

import java.util.Scanner;

/**
*
* @author asus第15章範例程式碼6 全桂群2017.4.9
*
*/
public class Verify {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//聲明變數
boolean fileCorrct=false; //標識檔案名稱是否正確
boolean emaiLCorrect=false; //標識E-mail是否正確
System.out.println("---歡迎進入作業提交系統---");
Scanner input = new Scanner(System.in);
System.out.println("請輸入java檔案名稱:");
String fileName=input.next();
System.out.println("請輸入你的郵箱:");
String email=input.next();
//檢查java檔案名稱
int index=fileName.lastIndexOf(".");//"."的位置
if(index!=-1&&index!=0&&fileName.substring(index+1, fileName.length()).equals("java")){
fileCorrct=true;
}else{
System.out.println("檔案名稱無效。");
}
//檢查你的郵箱格式
if(email.indexOf(‘@‘)!=-1&&email.indexOf(‘.‘)>email.indexOf(‘@‘)){
fileCorrct=true;

}else{
System.out.println("E-mail無效。");
}
//輸出檢測結果
if(fileCorrct&&fileCorrct){
System.out.println("作業提交成功!");
}else{
System.out.println("作業提交失敗!");
}
}

/**
*
* @author asus第15章範例程式碼7 全桂群2017.4.9
*
*/
public class Lyric {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String words="長亭外 古道邊 芳草碧連天 晚風扶 柳笛聲殘 夕陽山外山";
String[] printword=new String [100];//定義接收數
System.out.println("***原歌詞格式***\n"+words);
System.out.println("\n***拆分後歌詞格式***");
printword=words.split("");//按照空格進行拆分
for (int i = 0; i < printword.length; i++) {
System.out.println(printword[i]);//列印輸出
}
}

}

/**
*
* @author asus第15章範例程式碼8 全桂群2017.4.9
*
*/
public class sbAppend {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer("青春無悔");
int num = 110;
// 在字串後面追加字串
StringBuffer sb1 = sb.append("我心永恒");
System.out.println(sb1);
// 在字串後面追加字元
StringBuffer sb2 = sb1.append(‘啊‘);
System.out.println(sb2);
// 在字串後面追加整形數字
StringBuffer sb3 = sb2.append(num);
System.out.println(sb3);
}

}

import java.util.Scanner;

/**
*
* @author asus第15章範例程式碼9 全桂群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);
//接收字串,存放於StringBuffer類型的對象中
System.out.println("請輸入一串數字:");
String nums=input.next();
StringBuffer str=new StringBuffer(nums);
//從後往前每隔三位增加逗號
for (int i = str.length()-3; i >0; i=i-3) {
str.insert(i, ‘,‘);
}
System.out.println(str);
}

}

 

java第15章範例程式碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.