java代碼示例(2)
阿新 • • 發佈:2017-10-15
class ext name auth logs static chan eth 鍵盤
/** * 目的:求各位之和 * @author chenyanlong * 時間:2017/10/14 */ package com.hp.test02; import java.util.Scanner; public class HS_LuckyNumSum { public static void main(String[] args) { // TODO Auto-generated method stub int num; System.out.println("請輸入4位會員卡號:"); Scanner input=new Scanner(System.in); num=input.nextInt(); System.out.println("會員卡號是:"+num); System.out.println("千位:"+num/1000); System.out.println("百位:"+num/100%10); System.out.println("十位:"+num/10%10); System.out.println("個位:"+num%10); int sum=num/1000+num/100%10+num/10%10+num%10; System.out.println("會員卡號"+num+"各位之和:"+sum); } }
1 /** 2 * 目的:在控制臺打印個人簡歷信息 3 * @author chenyanlong 4 * 時間:2017/10/14 5 */ 6 package com.hp.test02; 7 8 public class HS_ShowMessage { 9 10 public static void main(String[] args) { 11 // TODO Auto-generated method stub 12 String name="黑石"; 13 int age=22; 14 charsex=‘男‘; 15 String position="java工程師"; 16 17 System.out.println("姓名:"+name); 18 System.out.println("年齡:"+age); 19 System.out.println("性別:"+sex); 20 System.out.print("職位:"+position); 21 22 } 23 }
1 /** 2 * 目的:Scanner的基本用法 3 * @author chenyanlong4 * 時間:2017/10/14 5 */ 6 package com.hp.test02; 7 8 import java.util.Scanner;//導入的Scanner類 9 10 public class HS_TypeChange { 11 12 public static void main(String[] args) { 13 // TODO Auto-generated method stub 14 int number;//會員卡號 15 System.out.println("請輸入會員卡號"); 16 17 Scanner input=new Scanner(System.in);//System.in系統鍵盤輸入 18 number=input.nextInt(); 19 System.out.println("會員卡號為:"+number); 20 } 21 22 }
java代碼示例(2)