Twin primes(雙生質數) are a pair of prime numbers that differ by 2. For example, 3 and 5 are twin primes, 5 and 7 are twin primes, and 11 and 13 are twin primes. Write a program to find all twin primes less than 1,000. Display the output as follows:
(3,5)
(5,7)
...
2014年12月27日 星期六
java程式設計題目---公式計算【梅森質數(使用method)】
A prime number is called a Mersenne prime(梅森質數) if it can be written in the form 2^p-1 for some positive integer p.
Write a program that finds all Mersenne prime with p<=31 and displays the output as follows:
p 2^p-1
2 3
3 7
5 31
...
Write a program that finds all Mersenne prime with p<=31 and displays the output as follows:
p 2^p-1
2 3
3 7
5 31
...
2014年12月26日 星期五
java程式設計題目---數字處理【迴文質數判斷(使用method)】
A palindromic prime is a prime number and also palindromic. For example, 131 is a prime and also a palindromic prime, as are 313 and 757. Write a program that displays the first 100 palindromic prime numbers. Display 10 numbers line, separated by exactly one space, as follows:
2 3 5 7 11 101 131 151 181 191
313 353 373 383 727 757 787 797 919 929
2 3 5 7 11 101 131 151 181 191
313 353 373 383 727 757 787 797 919 929
java程式設計題目---數字處理【迴文判斷(使用method)】
Write the methods with the following headers:
public static int reverse(int number)
public static Boolean isPalindrome(int number)
Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.
public static int reverse(int number)
public static Boolean isPalindrome(int number)
Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.
java程式設計題目---數字處理【數值反轉(使用method)】
Write a method with the following header to display an interger in reverse order:
public static int reverse(int number)
For example, reverse(3456) displays 6543. Write a test program that promotes the user to enter an integer and displays its reversal.
public static int reverse(int number)
For example, reverse(3456) displays 6543. Write a test program that promotes the user to enter an integer and displays its reversal.
java程式設計題目---字母處理【輸出字母、換行(使用method)】
Write a method that prints characters using the following header:
public static void printChars(char ch1, char ch2, int numberPerLine)
This method prints the characters between ch1 and ch2 with the specified numbers per line. Write a test program the prints ten characters per line from 1 to Z. Character are separated by exactly one space.
public static void printChars(char ch1, char ch2, int numberPerLine)
This method prints the characters between ch1 and ch2 with the specified numbers per line. Write a test program the prints ten characters per line from 1 to Z. Character are separated by exactly one space.
java程式設計題目---圖形繪製【使用2的n次方印三角形(使用method)】
Write a method to display a pattern as follows:
1
1 2
1 2 4
1 2 4 8
...
1 2 4 8 ....
The method header is
public static void displayPattern(int n)
1
1 2
1 2 4
1 2 4 8
...
1 2 4 8 ....
The method header is
public static void displayPattern(int n)
java程式設計題目---數字處理【由大到小排序(使用method)】
Write a method with the following header to display three numbers in decreasing order:
public static void displaySortedNumbers(double num1, double num2, double num 3)
Write a test program that prompts the user to enter three numbers and invokes the method to display them in decreasing order.
public static void displaySortedNumbers(double num1, double num2, double num 3)
Write a test program that prompts the user to enter three numbers and invokes the method to display them in decreasing order.
java程式設計題目---公式計算【判斷一年有幾天(使用method)】
Write a method that returns the number of days in a year using the following header:
public static int numberOfDaysInAYear(int year)
Write a test program that displays the number of days in year from 2000 to 2020.
public static int numberOfDaysInAYear(int year)
Write a test program that displays the number of days in year from 2000 to 2020.
java程式設計題目---數字處理【數字拆解(使用method)】
Write a method that computes the sum of the digits in an integer. Use the following method header:
public static int sumDigits(long n)
For example, sumDigits(234) returns 9 (2+3+4). Use a loop to repeatedly extract and remove the digit until all the digits are extracted. Write a test program thar prompts the user to enter an inter an integer and displays the sum of all its digits.
public static int sumDigits(long n)
For example, sumDigits(234) returns 9 (2+3+4). Use a loop to repeatedly extract and remove the digit until all the digits are extracted. Write a test program thar prompts the user to enter an inter an integer and displays the sum of all its digits.
2014年12月24日 星期三
java程式設計題目---數字處理【拆解後輸出(轉成String型態)】
設計一程式,提示使用者輸入一整數介於1~32767之間。將此整數拆解後於螢幕輸出。
例如:輸入4567,輸出4 5 6 7 。
java程式設計題目---圖形印製【三角形(2的m次方)】
設計一程式,提示使用者輸入正整數n,在螢幕上書出n層下列圖形。
例如:輸入5,輸出:
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
例如:輸入5,輸出:
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
java程式設計題目---數字處理【排列組合】
設計一程式,提示使用者輸入兩個整數m、n,接下來從螢幕輸出最小可能(m,n)到最大可能(m,n)的組合。
例如:輸入2,4,輸出:(2,3),(3,4)
例如:輸入2,4,輸出:(2,3),(3,4)
java程式設計題目---數字處理【十進位轉二進位】
設計一程式,提示使用者輸入正整數n,將該數值轉換成二進位數制,並以16-bit方式於螢幕輸出結果。
例如:輸入18,輸出 0000 0000 0001 0010。
例如:輸入18,輸出 0000 0000 0001 0010。
2014年12月23日 星期二
java程式設計題目---數字處理【平面座標位置判斷(矩形、矩形)】
設計一程式,提示使用者輸入兩個矩形的中心點(x,y)、長、寬。判斷第二個矩形是在第一個矩形的
1. 內部
2. 重疊
3. 無相交
1. 內部
2. 重疊
3. 無相交
java程式設計題目---公式計算【三角形類型判斷】
設計一程式,提示使用者輸入三角形的三個邊邊長,判斷此三角形為
1. 正三角形(三邊等長)
2. 等腰三角形(兩邊等長)
3. 不規則三角形(三邊等長)
4. 無法構成三角形(任意兩邊和小於或等於第三邊)
1. 正三角形(三邊等長)
2. 等腰三角形(兩邊等長)
3. 不規則三角形(三邊等長)
4. 無法構成三角形(任意兩邊和小於或等於第三邊)
java程式設計題目---數字處理【平面座標位置判斷】
設計一程式,提示使用者輸入平面座標值x,y,判斷座標點所在區域並輸出適當描述。(描述該點位於1. 原點 2. X軸 3. Y軸 4. 第n象限 )
java程式設計題目---數字處理【里程計算】
設計一程式,提示使用者輸入計程車里程,並計算費用後顯示於螢幕。里程計算方法如下:
里程(公尺) 費用
<1500 70元
>1500 每多500公尺+5元
*不足500公尺以500公尺計算
里程(公尺) 費用
<1500 70元
>1500 每多500公尺+5元
*不足500公尺以500公尺計算
java程式設計題目---數字處理【分數分級】
設計一個程式,提示使用者輸入分數,將其分數依照不同等級由螢幕輸出。分數分級如下:
等級 分數區間
A 90~100
B 80~89
C 70~79
D 60~69
E 0~59
等級 分數區間
A 90~100
B 80~89
C 70~79
D 60~69
E 0~59
java程式設計題目---數字處理【零錢兌換】
設計一個程式,提示使用者輸入金額,將此金額以100元、50元、20元、10元、5元、1元六種貨幣組合出該金額。組合方式為依照面額由大至小的順序使用貨幣,且每種貨幣的數量為無限多,無法使用100元時才能使用50元,無法使用50元時才可以使用20元,依此類推。由螢幕輸出計算結果。輸出格式為六個數字,第一個數字代表用幾個100元、第二個數字表示用幾個50元,依此類推。
例如: 輸入101,輸出: 1 0 0 0 0 1。
例如: 輸入101,輸出: 1 0 0 0 0 1。
java程式設計題目---數字處理【三位數拆解重組】
設計一程式,提示使用者輸入一個三位數整數,計算出此數值的每個位數後,將所有位數以相反順序重新組合成整數值,並將結果列印出。
例如:輸入 123,輸出321
例如:輸入 123,輸出321
java程式設計題目---字母轉換【數字轉字母】
設計一程式,提示使用者輸入正整數n,印出第n個小寫英文字母。
例如:輸入1,印出a
例如:輸入1,印出a
- import java.util.Scanner;
- public class C1
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("please enter a number:");
- int a = input.nextInt();
- int b = a + 96;
- System.out.println("The answer of the question is:" + (char)b);
- }
- }
訂閱:
文章 (Atom)
Go(Golang)程式語言 設定GCC
下載MSYS2: https://www.msys2.org/ 安裝 程式開始執行後輸入: pacman -Syu y y 在安裝目錄底下找到msys2.exe,雙擊執行 輸入指令: pacman -Su pacman -S --needed base-devel mingw-...
-
MNIST手寫數字辨識資料集 MNIST手寫數字辨識資料集 ,是由 Yann LeCun(揚·勒丘恩) 大神所蒐集,這位大神同時也是Convulution Nueral Networks(卷積神經網絡)的創始人,因此享有"卷積網絡之父"的美譽。關於這位大...
-
Write a program that reads an integer between 100 and 999, and show the result of the sum, product and difference of all its digits. For ex...
-
設計一程式,提示使用者輸入正整數n,判斷此數是否為質數並將結果印出。