本文主要介紹用戶交互體驗(yàn)(用戶交互是什么意思),下面一起看看用戶交互體驗(yàn)(用戶交互是什么意思)相關(guān)資訊。
基礎(chǔ)介紹1.n:把回車當(dāng)成了終結(jié)者。也就是說nextline方法返回輸入回車鍵之前的所有字符都可以得到空白的例子來顯示public class scanner dx { public static void main(string[]args){//創(chuàng)建一個(gè)scanner對象來接受鍵盤數(shù)據(jù)scanner = new scanner (system .在);system . out . println( 下次接收: );//判斷用戶是否輸入了字符串if (scanner.hasnext){//表示正確:scanner.hasnext=true,and =true //可以省略,下一種接收字符串str = scanner . next;//程序會等待用戶輸入(用戶輸入:hello world)system . out . println( 輸出內(nèi)容: str);//輸出內(nèi)容為:hello } system . out . println( 由nextline接收: );string string = scanner . nextline;//(用戶輸入:hello world)system . out . println( 輸出內(nèi)容: 弦與弦);//輸出內(nèi)容為:hello world //所有屬于io流的類,如果不關(guān)閉,會一直占用資源。養(yǎng)成一個(gè)好習(xí)慣,完成后關(guān)閉scanner . close;//實(shí)例掃描器scanner1 =新掃描器(系統(tǒng)。在);system . out . println( 請輸入整數(shù): );int i = 0;if(scanner 1 . hasnextint){ i = scanner 1 . nextint;system . out . println( 輸出整數(shù):i);} else { system . out . println( 輸出數(shù)據(jù)不是整數(shù)。 );} float f=0。0f;system . out . println( 請輸入一個(gè)小數(shù) );if(scanner 1 . hasnextfloat){ f = scanner 1 . nextfloat;system . out . println( 輸出十進(jìn)制是 f );} else { system . out . println( 輸出數(shù)據(jù)不是十進(jìn)制的。 );} scanner 1 . close;}}標(biāo)簽:
整數(shù)字符
了解更多用戶交互體驗(yàn)(用戶交互是什么意思)相關(guān)內(nèi)容請關(guān)注本站點(diǎn)。