Doing Java, Java homework writing, Java homework doing String class, StringBuffer class, Jbulider tool development

Java, Java homework writing, Java homework acting as String class, StringBuffer class
experiment five common APIs
1. Experiment purpose and requirements
1. Understand the use of inner classes
2. Master the use of exception classes
3. Understand and master the String class, StringBuffer class
2. Experiment content
(1) The inner class
runs the following programs, understands the use of the inner class, and analyzes and explains the running results.
class Cry{
public void cry(){
System.out.println("Hello everyone");
}
}
public class KY5_1 {

public static void main(String[] args) {
Cry hello = new Cry(){
public void cry(){
System.out.println("Hello everyone, good luck with your work!");
}
};
hello.cry( );
}
}
(2) Exception class
When dividing two numbers, the divisor cannot be 0. If the divisor is 0, an Exception will be thrown. Use the try...catch statement to handle the exception, catch the exception and process it by the catch code block, and print out the exception information. Regardless of whether an exception occurs or not, it is required to output "During division, the divisor cannot be 0.".
public class KY5_2 {
public static void main(String[] args) {
//The following code defines a try...catch...finally statement to catch exceptions
{
int result = divide(4, 0); //call divide() Method
System.out.println(result);
} { //Process the captured exception
System.out.println("The captured exception information is: " + e.getMessage());
return; //Used to end Current method
} { //Fill in the required keyword
System.out.println("In division, the divisor cannot be 0.");
}
System.out.println("The program continues to execute down...");
}
//The following method implements the division of two integers, and uses the throws keyword to declare that an exception is thrown
public static int divide(int x, int y ) Exception {
int result = x / y; //Define a variable result to record the result of dividing two numbers
return result; //Return the result
}
}
Requirement: Please complete the code and write the source code and running result of the program on the lab report.

(3) The use of String class and StringBuffer class
1. Use the following key code to write a complete program KY5_3.java to understand the use of String and StringBuffer.
String s=new String("This is an demo of the String method.");
System.out.println("Length: "+s.length());
System.out.println("SubString: "+s. substring(11,15));
StringBuffer sf=new StringBuffer("Hello World!");
sf.append("Hello Java!");
sf.insert(12,"And");
System.out.println(sf );
System.out.println(sf.charAt(0));
sf.setCharAt(0,''h'');
System.out.println(sf.charAt(0));
System.out.println(sf );

2. Write the results of the program in the lab report.


3. Experimental equipment and environment
Windows7 and above systems, install eclipse+JDK
4. Experimental process and results

V. Experiment Summary
http://www.6daixie.com/contents/9/1338.html

Our field of direction: window programming, numerical algorithm, AI, artificial intelligence, financial statistics, econometric analysis, big data, network programming, WEB programming, communication programming, game programming, multimedia linux, plug-in programming program, API, image processing, embedded/MCU database programming, console process and thread, network security, assembly language hardware Programming software design engineering standards and regulations. The ghostwriting and ghostwriting programming languages ​​or tools include but are not limited to the following:

C/C++/C# ghostwriting

Java ghostwriting

IT ghostwriting

Python ghostwriting

Tutored programming assignments

Matlab ghostwriting

Haskell ghostwriting

Processing ghostwriting

Building a Linux environment

Rust ghostwriting

Data Structure Assginment

MIPS ghostwriting

Machine Learning homework ghostwriting

Oracle/SQL/PostgreSQL/Pig database ghostwriting/doing/coaching

web development, website development, website work

ASP.NET website development

Finance Insurance Statistics Statistics, Regression, Iteration

Prolog ghostwriting

Computer Computational method

 

Because professional, so trustworthy. If necessary, please add QQ: 99515681 or email: [email protected]

WeChat: codinghelp

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325061520&siteId=291194637