Summary & fifth week experiment

                                                              Week Summary

1.final variable declaration becomes constant, constant can not be modified.

 

 

2. The subclasses can inherit public and protected member variables of the parent class but can not inherit private member variable of the parent class;
packet access member variables of the parent class, lower class if the child and parent classes in the same package, it subclasses can be inherited;
for subclasses can inherit the parent class member variables, if there is a member variable of the same name in the subclass, member variables subclass will shield the same name member variables of the parent class; if you want to visit a parent in a subclass class member variables of the same name, need to use the super keyword to reference;
inherit public and protected members of the parent class; can not inherit the private members of the parent class;
package access members of the parent class method when the child class and parent class in the same package, a subclass can inherit, otherwise, the subclass can not inherit;
parent class member method subclasses can inherit, if there is a member methods with the same name in the subclass is called covering, namely child members of the methods of the class members with the same name will overwrite the parent class. If you want to access the same name in the subclass members parent class, you need to use the super keyword to reference;
hiding is for member variables and static methods, coverage is for the ordinary method;
subclass can not inherit the parent class's constructor, note that if is the parent class constructor with parameters, you must call the parent class constructor by the super keyword in the constructor subclass if the parent class has no argument constructor, the constructor of the subclass can not super keyword, if you do not use the super keyword, the system will automatically call;

 

3. Want to use the Scanner requires the following three steps

 

 

 

1, the first line of the Java class util Scanner Import;
2, before the need to enter the scanner y = new Scanner (system.in) ; // the object
3, to let him work by y int = nextInt (), string = nextline (); can read information input

                                                                        Experimental Report III sjh 20188393

 

Application third experiment String class

Purpose
using master class String class;
learn to use JDK help files;
experiment content
1. Known string: "this is a test of java " required to do the following requirements :( source code, the results screenshot).

The number of letters in the string s occurs statistics.
The string neutron count the number of times the string "is" appears.
The number of words in the string "is" appears in the statistics.
Achieve reverse the string is output.
2. Write a program, using the following algorithm to encrypt or decrypt the English string input by the user. It requires source code, the results screenshot.

3. Given the string "ddejidsEFALDFfnef2357 3ed". The output string in the number of capital letters, lowercase letters count, the number of non-English letters.

1. Known string: "this is a test of java" required to do the following requirements :( source code, the results screenshot).

The number of letters in the string s occurs statistics.

The string neutron count the number of times the string "is" appears.

The number of words in the string "is" appears in the statistics.

Achieve reverse the string is output.

Error

when it 'is' invalid character constants together
summarize this question the teacher talked about in class and then use it in a book summary p111-117 Kazakhstan

2. Write a program, using the following algorithm to encrypt or decrypt the English string input by the user. Requires source code, the results screenshot

Code

package 实验报告三;
import java.util.Scanner;
public class 题2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String s = ""; char[] charArray = str.toCharArray(); for (int i = 0; i < charArray.length; i++) { s += (char)((int)charArray[i]+3); } System.out.println(s); } }


I think this is not a question I got it wrong, enter the number of words each plus three output but then there will be other characters when input English words and numbers greater than seven do not know if it counted an encrypted process.

3. Given the string "ddejidsEFALDFfnef2357 3ed". The output string in the number of capital letters, lowercase letters count, the number of non-English letters.

package 实验报告三;

public class 题3 {
    
         

               public static void main(String[] args) { String str = "ddejidsEFALDFfnef2357 3ed"; char [] c = str.toCharArray(); //public char[] toCharArray()将字符串转成char字符数 //字符串转为二进制数组,二进制转回字符串 int i, sumDX = 0, sumXX = 0, sumQT = 0; for(i=0;i<c.length;i++) { if(c[i]>='A'&&c[i]<='Z') { sumDX = sumDX + 1; } else if(c[i]>='a'&&c[i]<='z') { sumXX = sumXX + 1; } else { sumQT = sumQT + 1; } } System.out.println("大写字母数为:"+sumDX); for(i=0;i<c.length;i++) { if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') { System.out.print(str.charAt(i)); } } System.out.println("\n"+"小写字母数为:"+sumXX); for(i=0;i<c.length;i++) { if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') { System.out.print(str.charAt(i)); } } System.out.println("\n"+"非英文字母数为:"+sumQT); for(i=0;i<c.length;i++) { if(str.charAt(i)<'A'||str.charAt(i)>'z') { System.out.print(str.charAt(i)); } } } } 

 

to sum up

 

Guess you like

Origin www.cnblogs.com/songjiah/p/11600625.html