這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)java實(shí)現(xiàn)從鍵盤獲取數(shù)據(jù)的方法,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
import java.util.Scanner;// 導(dǎo)包, 找到Scanner的位置 public class TestScore{ public static void main(String [] args){ //Scanner ,描掃儀 //【1】創(chuàng)建Scanner對象, System.in標(biāo)準(zhǔn)的輸入設(shè)備,鍵盤 Scanner input=new Scanner(System.in); //input是描掃儀的名稱,自己起,變量的命名規(guī)則 //【2】給用戶友好提示 System.out標(biāo)準(zhǔn)的輸出設(shè)備,顯示器 System.out.print("請輸入java課程的分?jǐn)?shù):"); //聲明變量并賦值 int javaScore= input.nextInt(); //從鍵盤錄入一個(gè)整數(shù)賦值給int類型的變量 javaScore System.out.print("請輸入sql課程的分?jǐn)?shù):"); int sqlScore=input.nextInt(); System.out.print("請輸入stb課程的分?jǐn)?shù):"); int stbScore=input.nextInt(); int diffen; //聲明變量,用于存儲(chǔ)分?jǐn)?shù)差 double avg;// 聲明變量,用于存儲(chǔ)平均分 //給分?jǐn)?shù)差及平均分賦值 diffen=javaScore-sqlScore; //賦值是從右到左 avg=(javaScore+sqlScore+stbScore)/3; //avg=(javaScore+sqlScore+stbScore)/3.0; System.out.println("-------------------------------"); System.out.println("java\tsql\tstb"); System.out.println(javaScore+"\t"+sqlScore+"\t"+stbScore); System.out.println("-------------------------------"); System.out.println("java與sql的差是:"+diffen); System.out.println("三門課程的平均分為:"+avg); } }
import java.util.Scanner; public class HelloWorld{ public static void main(String [] args ){ Scanner input=new Scanner(System.in); System.out.print("請輸入java的成績"); int javaScore=input.nextInt(); System.out.print("請輸入python成績"); int pythonScore=input.nextInt(); System.out.println("請輸入C語言的成績"); int cScore=input.nextInt(); int avg=(javaScore+pythonScore+cScore)/3; int diffen; diffen=javaScore-pythonScore; System.out.println("各門功課的成績?yōu)椋篭t"+"javaScore \t"+"pythonScore\t"+"cScore"); System.out.println("各門功課的成績?yōu)椋篭t"+javaScore+"\t"+pythonScore+"\t"+cScore); System.out.println("java和python的成績差為:"+diffen); } }
SQL語句:Structured Query Language
標(biāo)準(zhǔn)的輸入設(shè)備:鍵盤,System.in
標(biāo)準(zhǔn)的輸出設(shè)備:電腦屏幕,System.out
創(chuàng)建Scanner對象:Scanner input=new Scanner(System.in);
上述就是小編為大家分享的java實(shí)現(xiàn)從鍵盤獲取數(shù)據(jù)的方法了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章題目:java實(shí)現(xiàn)從鍵盤獲取數(shù)據(jù)的方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://jinyejixie.com/article36/dphepg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、靜態(tài)網(wǎng)站、App設(shè)計(jì)、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站內(nèi)鏈、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容