This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; | |
| public class RainOrNot { | |
| public static void main(String[] args) { | |
| int rand; | |
| rand = (int)(Math.random()*10)+1; //亂數取1~10 | |
| System.out.println("亂數 = " + rand); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; | |
| public class HomeWork_05_adv { | |
| //請設計一個方法void genAuthCode(),當呼叫此方法時,會回傳一個8位數的驗證碼,此驗證碼內容包含了英文大小寫與數字的亂數組 | |
| public void genAuthCode() { | |
| int[]code=new int[8]; | |
| int r; | |
| for (int i=0;i<code.length;i++) { | |
| while(true) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; | |
| //請設計一個類別MyRectangle | |
| public class HomeWork_05_MyRectangle { | |
| //有兩個double型態的屬性為width, depth | |
| private double width; | |
| private double depth; | |
| //有三個方法 | |
| public void setWidth(double width){ | |
| this.width =width; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; | |
| import java.util.Scanner; | |
| public class HomeWork_05_Main { | |
| public static void main (String[] args) { | |
| //利用Overloading,設計兩個方法double maxElement(int x[][])與double maxElement(double x[][]),可以找出二維陣列的最大值並回傳 | |
| System.out.println("利用Overloading,設計兩個方法double maxElement(int x[][])與double maxElement(double x[][]),可以找出二維陣列的最大值並回傳"); | |
| int[][] intArray = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; | |
| import java.util.Scanner; | |
| public class HomeWork_05_Main { | |
| public static void main (String[] args) { | |
| //請設計一個方法為randAvg(),從10個 0~100(含100)的整數亂數中取平均值並印出這10個亂數與平均值 | |
| System.out.println("請設計一個方法為randAvg(),從10個 0~100(含100)的整數亂數中取平均值並印出這10個亂數與平均值"); | |
| HomeWork_05_Method h2 = new HomeWork_05_Method(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; | |
| import java.util.Scanner; | |
| public class HomeWork_05_Main { | |
| public static void main (String[] args) { | |
| //請設計一個方法為starSquare(int width, int height),當使用者鍵盤輸入寬與高時,即會印出對應的*長方形 | |
| System.out.println("請設計一個方法為starSquare(int width, int height),當使用者鍵盤輸入寬與高時,即會印出對應的*長方形"); | |
| int width, height; | |
| Scanner a =new Scanner(System.in); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //班上有8位同學,他們進行了6次考試,請算出每位同學考最高分的次數 | |
| System.out.println("班上有8位同學,他們進行了6次考試,請算出每位同學考最高分的次數"); | |
| int[][]exam= { | |
| {10,35,40,100,90,85,75,70}, | |
| {37,75,77,89,64,75,70,95}, | |
| {100,70,79,90,75,70,79,90}, | |
| {77,95,70,89,60,75,85,89}, | |
| {98,70,89,90,75,90,89,90}, | |
| {90,80,100,75,50,20,99,75}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //請設計一隻程式由鍵盤輸入三個整數,分別代表西元yyyy年,mm月,dd日,它會顯示是該年的第幾天 | |
| System.out.println("請設計一隻程式由鍵盤輸入三個整數,分別代表西元yyyy年,mm月,dd日,它會顯示是該年的第幾天"); | |
| int[] d1= {31,28,31,30,31,30,31,31,30,31,30,31}; | |
| Scanner dsc = new Scanner(System.in); | |
| System.out.println("請輸入西元年(yyyy)="); | |
| int yy=dsc.nextInt(); | |
| System.out.println("請輸入月(mm)="); | |
| int mm=dsc.nextInt(); | |
| int dd; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //請設計一個程式,可以讓小華輸入欲借的金額後,便會顯示哪些員工編號的同事有錢可借他;並且統計有錢可借的總人數 | |
| System.out.println("請設計一個程式,可以讓小文輸入欲借的金額後,便會顯示哪些員工編號的同事有錢可借他;並且統計有錢可借的總人數"); | |
| int[][] c1= { | |
| {25, 32, 8, 19, 27}, | |
| {2500, 800, 500, 1000, 1200} | |
| }; | |
| int count=0; | |
| Scanner sc = new Scanner(System.in); | |
| System.out.println("輸入小文欲借的金額="); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.Scanner; | |
| public class HomeWork_04 { | |
| public static void main (String[] args) { | |
| //請寫出一隻程式能輸出陣列所有元素的平均值與大於平均值的元素 | |
| System.out.println("請寫出一隻程式能輸出陣列所有元素的平均值與大於平均值的元素"); | |
| int[] i1 = {29, 100, 39, 41, 50, 8, 66, 77, 95, 15}; |
NewerOlder