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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java(肆)

發布時間:2025/4/14 java 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java(肆) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第五周課程總結:

? ?

實驗三?String類的應用

  • 實驗目的
  • 掌握類String類的使用;
  • 學會使用JDK幫助文檔;
  • 實驗內容

1.已知字符串:"this is a test of java".按要求執行以下操作:(要求源代碼、結果截圖。)

  • 1.統計該字符串中字母s出現的次數。
  • 實驗源碼:
  • public class text1 {
    ?public static void main(String[] args) {
    ??????? String str="this is a test of java";
    ??????? int count=0;
    ??????? char c[]=str.toCharArray();
    ??????? for(int i=0;i<c.length;i++){
    ??????????? if(c[i]=='s'){
    ??????????????? count++;
    ??????????? }??????????
    ???????? }
    ??????? System.out.println("s出現了"+count+"次");
    ???????????
    ??? } }
  • 截圖:
  • 2.統計該字符串中子串“is”出現的次數。
  • 實驗源碼:
  • public class texe2 {
    ?public static void main(String[] args) {
    ??????? String str = "this is a test of java";
    ??????? int count = 0, index = 0;
    ??????? while (true) {
    ??????????? int n = str.indexOf("is", index);
    ??????????? if (n != -1) {
    ??????????????? index = n + 1;
    ??????????????? count++;
    ??????????? } else {
    ??????????????? break;
    ??????????? } }
    ??????? System.out.print("is出現了" + count + "次");
    ??? }
    }
  • 截圖:
  • 3.統計該字符串中單詞“is”出現的次數
  • 實驗源碼:
  • public class text3 {
    ?public static void main(String[] args) {
    ??????? int count=0;
    ??????? String str="this is a test of java";
    ??????? String s[]=str.split(" ");
    ??????? for(int i=0;i<s.length;i++){
    ??????????? if(s[i].equals("is")){
    ??????????????? count++;???????
    ??????????? } }
    ??????? System.out.println(count);
    ??? }
    }
  • 截圖:

?

?

  • 4.實現該字符串的倒序輸出。
  • 實驗源碼:
  • public class text4 {
    ?public static void main(String[] args) {
    ??????? String str = "this is a test of java";
    ??????? char s[] = str.toCharArray();
    ??????? for (int i=s.length-1;i>=0;i--) {
    ??????????? System.out.print(s[i]); } }
    }
  • 截圖:
  • 總結:老師上課的時候基本都通過eclipse為我們演示了一遍,基本操作就是這么一個情況;

2.請編寫一個程序,使用下述算法加密或解密用戶輸入的英文字串。要求源代碼、結果截圖。

?

實驗源碼:

import java.util.*;
public class text1 {
?public static void main(String[] args) {
??????? System.out.print("輸入一個字符串:");
??????? var scanner = new Scanner(System.in);
??String str1 = scanner.nextLine();
??????? System.out.println(str1);
??????? char c[] = str1.toCharArray();
??????? int ASCII;
??????? char c1;
??????? for (int i = 0; i < c.length; i++) {
??????????? ASCII = c[i] + 3;
??????????? // System.out.print(ASCII+" ");
??????????? c1 = (char) ASCII;
??????????? // System.out.print(c1+" ");
??????????? String s = String.valueOf(c1);
??????????? System.out.print(s); } }
} 截圖:

?

?

?3.已知字符串“ddejidsEFALDFfnef2357 3ed”。輸出字符串里的大寫字母數,小寫英文字母數,非英文字母數。

實驗源碼:

public class text1 {
?public static void main(String[] args) {
??????? String str = "adhadhahdhahhH 1231";
??????? char c[] = str.toCharArray();
??????? int count1 = 0, count2 = 0, count3 = 0;
??????? for (int i = 0; i < c.length; i++) {
??????????? int n = (int) c[i];
??????????? if (65 <= n && n <= 90) {
??????????????? count1++;
??????????? } else if (97 <= n && n <= 122) {
??????????????? count2++;
??????????? } else {
??????????????? count3++;
??????????? } }
??????? System.out.println("大寫字母數:" + count1);
??????? System.out.println("小寫字母數:" + count2);
??????? System.out.println("非英文字母數:" + count3); }
?
} 截圖:

?

?

?課程總結:

表格:

繼承(extends);

方法的重載與覆寫的區別:

區別點

重載

覆寫

單詞

Overloading

Overriding

定義

方法名稱相同,參數的類型或個數不同

方法名稱、參數類型、返回值類型全部相同

定義

對權限沒有要求

被覆寫的方法中不能有更嚴格的權限

范圍

發生在一個類中

發生在繼承中

super關鍵字的使用;

final關鍵字:類&屬性&方法;

.....受益匪淺.....

樸實無華且枯燥

?

轉載于:https://www.cnblogs.com/lsy2380821-/p/11598865.html

總結

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

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