日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

工预-java3

發布時間:2025/3/15 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 工预-java3 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • JAVA基本計算方法和文件讀取的應用
    • A. 編程實現一個命令窗程序,使得:
      • 代碼
    • B. 編程實現一個命令窗程序,使得:
      • 代碼
    • C. 編程實現一個命令窗程序,使得:
      • 代碼

JAVA基本計算方法和文件讀取的應用

Java中獲取鍵盤輸入值,Scanner類。
equals,對比。

A. 編程實現一個命令窗程序,使得:

輸入“A”則在屏上回顯“Your input is A”輸入“我”則在屏上回顯“Your input is 我”等等。輸入ByeBye則退出程序.

代碼

import java.util.Scanner;//鍵盤輸入語法 public class HX1 { public static void main(String[] args)throws java.io.IOException {Scanner cen=new Scanner(System.in);//鍵盤輸入while(true)//循環{System.out.println("input your word "); String str=cen.nextLine();//鍵盤輸入if(!str.equals("byebye"))//鍵盤輸入內容對比{System.out.println(" your word is "+str);} else{System.out.println("end");System.exit(0);}}} }

編譯結果

運行結果

B. 編程實現一個命令窗程序,使得:

輸入“A”則在屏上回顯A字符的ASCII碼。輸入“4”則在屏上回顯4字符的ASCII碼。輸入“我”則在屏上回顯“我”字的漢字內碼。

等等。

輸入ByeBye則退出程序.

代碼

public static void main(String[] args)throws java.io.IOException{Scanner cen=new Scanner(System.in);//鍵盤輸入while(true)//循環{System.out.println("input your word "); String str=cen.nextLine();//鍵盤輸入if(!str.equals("byebye"))//鍵盤輸入內容對比{System.out.println((int)str.charAt(0)); //這個語法可以強行轉換為ASCII碼} else{System.out.println("end");System.exit(0);}}}}

編譯結果

運行結果

C. 編程實現一個命令窗程序,使得:

輸入“你”則在屏上回顯“you”。輸入“書”則在屏上回顯“book”。輸入“中”則在屏上回顯“middle”。輸入“中國”則在屏上回顯“China”。...要能輸入至少100個詞。如輸入沒有記錄的詞則如下:輸入“東東”則在屏上回顯“查不到該詞”。輸入ByeBye則退出程序.(提示: 單詞字典應做一個文本文件讀入,其中每行為:<中文字詞><對應英文> )

代碼

import java.io.BufferedReader; import java.io.IOException; import java.util.Scanner; import java.io.FileReader;public class HX3 {public static void main(String[] args) throws java.io.IOException {Scanner cen = new Scanner(System.in);// 鍵盤輸入while (true) {System.out.println("input your word ");String str = cen.next();// 鍵盤輸入FileReader word = new FileReader("E:\\javap\\dic.txt");// 讀取文本BufferedReader t = new BufferedReader(word);String c = "";// 一個空字符串boolean h=false;//定義布爾型變量用來查不到文本的詞while ((c = t.readLine()) != null) // 讀每行文本{// 得到文本的漢字,英文String chinese = c.substring(c.indexOf("<") + 1, c.indexOf(">"));String english = c.substring(c.lastIndexOf("<") + 1, c.lastIndexOf(">"));if (str.equals(chinese)) {// 對比中文,得出英文System.out.println(english);h=true;}if (str.equals("byebye")) {// 輸入byebye結束System.out.println("end");System.exit(0);}if(!h) {System.out.println("查不到該詞");}}}} }

編譯結果

運行結果

參考
https://me.csdn.net/yga_airspace
https://me.csdn.net/atishoo_13
https://me.csdn.net/yangchenju

總結

以上是生活随笔為你收集整理的工预-java3的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。