import java.util.Scanner;
public class C1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//請使用者輸入顯示數字範圍
System.out.println("請輸入起始數字:");
int start = input.nextInt();
System.out.println("請輸入結束數字:");
int end = input.nextInt();
int countwhile = 0;
int countfor = 0;
int number = start;
while(start == end || start > end)
{
countfor = countfor - 100;
countwhile = countwhile - 100;
System.out.println("沒有結果"); break;
}
for(int n = start ; n <= end ; n++)//使用for loop 撰寫程式
{
countfor = countfor + 1;
if( countfor % 7 != 0 && countfor > 0)
{
System.out.printf("%7d",n);
}
else if(countfor % 7 == 0 && countfor > 0 )
{
System.out.printf("%7d\n",n);
}
}
System.out.println("");//幫助排版更清楚
System.out.println("");//幫助排版更清楚
while( number <= end && countwhile >= 0 )//使用while loop 撰寫程式
{
countwhile = countwhile + 1;
if(countwhile % 7 != 0)
{
System.out.printf("%7d",number);
}
else if(countwhile % 7 == 0)
{
System.out.printf("%7d\n",number);
}
number = number + 1;
}
}
}
2014年7月12日 星期六
java程式設計題目---數字處理【(for loop && while loop)輸出、換行】
設計一個程式,由使用者從螢幕輸入正整數n、m,將n至m所有整數由小至大印出,但每列指印出最多7個數字,如果輸入m小於(等於)n,則輸出沒有結果。【使用for loop 和 while loop 撰寫】(每一橫排、直排皆須對齊)範例如下:
訂閱:
張貼留言 (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...
-
顯示語言 在一班情況下, Vsiual Studio Code (VSCode) 安裝完成後為英語版本,當然它也附有其他九種語言,分別是:英文(美國)、簡體中文、繁體中文、法文、德文、義大利文、日文、韓文、俄文、西班牙文。各個語言與其代碼對照如下表: Display ...

沒有留言:
張貼留言