課程
/后端開發
/Java
/Java入門第一季(IDEA工具)升級版
用for循環怎么做
2017-05-09
源自:Java入門第一季(IDEA工具)升級版 4-15
正在回答
public class HelloWorld{
public static void main(String[] args){
int num = 999;
if (num >= 0? && num<=999999999){
? for(int count = 0;num != 0;?count++){
?num/=10;
}
?System.out.println("它是個"+ count+"位的數!");
?} else{
?System.out.println("輸入有誤!");
?}
#include<iostream>using namespace std;int main(){??? int num;??? cin >> num ;??? int S1 = 1, S2 = 10;??? for(int i = 1; i <= 10; i++)??? {
??????? if(num >= S1 && num <= S2)??????? {??????????? cout << i << endl;??????????? break;??????? }??????? else??????? {??????????? S1 *= 10;??????????? S2 *= 10;??????? }??? }??? return 0;}
for(int i=0;i<10;i++)
{
? ? if(num>0)
? ? {
? ? ? ? num/=10;
? ? ? ? count++;
? ? }
System.out.println("它是個"+count+"位的數!");
舉報
0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始
2 回答判斷一個數(小于10位)的位數。 輸入999,則輸出 “它是個3位的數!”
2 回答判斷一個數(小于10位)的位數。 輸入999,則輸出 “它是個3位的數!
1 回答判斷一個數(小于10位)的位數。 輸入999,則輸出 “它是個3位的數!
6 回答判斷一個數(小于10位)的位數。 輸入999,則輸出 “它是個3位的數!”
6 回答判斷一個數(小于10位)的位數。 輸入999,則輸出 “它是個3位的數!
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-05-11
public class HelloWorld{
public static void main(String[] args){
int num = 999;
if (num >= 0? && num<=999999999){
? for(int count = 0;num != 0;?count++){
?num/=10;
}
?System.out.println("它是個"+ count+"位的數!");
?} else{
?System.out.println("輸入有誤!");
?}
?}
}
2017-05-09
#include<iostream>
using namespace std;
int main()
{
??? int num;
??? cin >> num ;
??? int S1 = 1, S2 = 10;
??? for(int i = 1; i <= 10; i++)
??? {
??????? if(num >= S1 && num <= S2)
??????? {
??????????? cout << i << endl;
??????????? break;
??????? }
??????? else
??????? {
??????????? S1 *= 10;
??????????? S2 *= 10;
??????? }
??? }
??? return 0;
}
2017-05-09
for(int i=0;i<10;i++)
{
? ? if(num>0)
? ? {
? ? ? ? num/=10;
? ? ? ? count++;
? ? }
}
System.out.println("它是個"+count+"位的數!");