当前位置:网站首页>one hundred and twenty-three thousand four hundred and fifty-six
one hundred and twenty-three thousand four hundred and fifty-six
2022-07-05 21:20:00 【The adventures of little fish Part I】
2 month
1. loop
/*public class q1 {
public static void main(String[] args){
int i,j;
for (i=1;i<=9;i++){
for (j=1;j<=i;j++){
System.out.print("*");
}
System.out.print("\n");
}
}
}
*/
2. School
class Student{
String name;
int age;
static String school = "A university ";
public Student(String name , int age){
this.name = name;
this.age = age;
}
public void info() {
System.out.println(" full name :"+this.name+", Age :"+this.age+", School :"+this.school);
}
}
public class Example14 {
public static void main(String[] args){
Student stu1=new Student(" Zhang San ",18);
Student stu2=new Student(" Li Si ",19);
Student stu3=new Student(" Wang Wu ",20);
stu1.info();
stu2.info();
stu3.info();
stu1.school = "B university ";
System.out.println(" modify stu1 The school information of the school object is B After college ");
stu1.info();
stu2.info();
stu3.info();
}
}
3. Sheepdog color
interface Animal {
public String NAME = " Shepherd Dog ";
public void info();
}
interface Color {
public void black();
}
interface Action extends Animal,Color{
public void shout();
}
class Dog implements Action{
public void info() {
System.out.println(" name :"+NAME);
}
public void black() {
System.out.println(" black ");
}
public void shout() {
System.out.println(" Wang Wang ......");
}
}
class Example13 {
public static void main(String[] args) {
Dog dog = new Dog();
dog.info();
dog.shout();
dog.black();
}
}
4. Cat dog polymorphism
abstract class Animal {
abstract void shout();
}
class Cat extends Animal {
public void shout(){
System.out.println(" Meow meow .......");
}
}
class Dog extends Animal {
public void shout() {
System.out.println(" Wang Wang ......");
}
}
public class Example14 {
public static void main(String [] args) {
Animal an1 = new Cat();
Animal an2 = new Dog();
an1.shout();
an2.shout();
}
}
5. Xiaohua meow
interface Animal{
void shout();
}
public class floret {
public static void main (String [] args) {
String name = " floret ";
animalShout(new Animal() {
@Override
public void shout() {
System.out.println(name+" Meow meow ");
}
});
}
public static void animalShout(Animal an){
an.shout();
}
}
6.io1
import java.io.File;
public class Example1 {
public static void main(String [] args){
File f = new File("D:\\file\\a.txt");
File f1 = new File("src\\Hello.java");
System.out.println(f);
System.out.println(f1);
}
}
7.io2
import java.io.File;
import java.io.IOException;
public class Example3 {
public static void main(String[]args)throws IOException {
File f=File.createTempFile("incast-",".txt");
f.deleteOnExit();
System.out.println("f Is it a document :"+f.isFile());
System.out.println("f Relative path of :"+f.getPath());
}
}
8. Byte stream read
/*import java.io.*;
public class ZH1 {
public static void main(String[] args)throws Exception{
FileInputStream in=new FileInputStream("test.txt");
int b=0;
while(true){
b=in.read();
if(b==-1){
break;
}
System.out.println(b);
}
in.close();
}
}
*/
9. Byte stream write
/*import java.io.*;
public class ZH3 {
public static void main(String[] args)throws Exception{
OutputStream out=new FileOutputStream("example2.txt",true);
String str=" Welcome ";
byte[] b=str.getBytes();
for(int i=0;i<b.length;i++){
out.write(b[i]);
}
out.close();
}
}
*/
10. File replication
/*import java.io.*;
public class ZH4 {
public static void main(String[] args)throws Exception{
InputStream in=new FileInputStream("source/a.png");
OutputStream out=new FileOutputStream("target/b.png");
int len;
long begintime=System.currentTimeMillis();
while ((len=in.read())!=-1){
out.write(len);
}
long endtime=System.currentTimeMillis();
System.out.println(" The time spent copying files is :"+(endtime-begintime)+"ms");
in.close();
out.close();
}
}
*/
11. Threads
/*public class SH2 {
public static void main(String[] args) {
MyThread02 myThread02 = new MyThread02();
myThread02.start();
while (true){
System.out.println("main Method is running ");
}
}
}
class MyThread02 extends Thread{
public void run(){
while (true){
System.out.println("MyThread Class run() Method is running ");
}
}
}
*/
12. Multithreading
/*public class SH3 {
public static void main(String[] args) {
MyThread03 myThread = new MyThread03();
Thread thread=new Thread(myThread);
thread.start();
while (true){
System.out.println("main() Method is running ");
}
}
}
class MyThread03 implements Runnable{
public void run(){
while (true){
System.out.println("MyThread Class run Method is running 0");
}
}
}*/
13. Comparison between threading and multithreading
/*public class SH5 {
public static void main(String[] args){
new TicketWindow().start();
new TicketWindow().start();
new TicketWindow().start();
new TicketWindow().start();
}
}
class TicketWindow extends Thread {
private int tickets = 100;
public void run() {
while (tickets > 0) {
Thread th = Thread.currentThread();
String th_name = th.getName();
System.out.println(th_name + " The second... Is on sale " + tickets-- + " Tickets ");
}
}
}*/
14. Selling tickets
public class SH6 {
public static void main(String[] args){
TicketWindow tw=new TicketWindow();
new Thread(tw," window 1").start();
new Thread(tw," window 2").start();
new Thread(tw," window 3").start();
new Thread(tw," window 4").start();
}
}
class TicketWindow extends Thread {
private int tickets = 100;
public void run() {
while (tickets > 0) {
Thread th = Thread.currentThread();
String th_name = th.getName();
System.out.println(th_name + " The second... Is on sale " + tickets-- + " Tickets ");
}
}
}
15. File replication 2
/*import java.io.*;
public class ZH5 {
public static void main(String[] args)throws Exception{
InputStream in=new FileInputStream("source/a.png");
OutputStream out=new FileOutputStream("target/a.png");
byte[] buff=new byte[1024];
int len;
long begintime=System.currentTimeMillis();
while ((len= in.read(buff))!=-1){
out.write(buff,0,len);
}
long endtime=System.currentTimeMillis();
System.out.println(" The time spent copying files is :"+(endtime-begintime)+"ms");
in.close();
out.close();
}
}
*/
16. Pick up io1 after try finall
public static void main(String[] args)throws Exception{
InputStream input = null;
try{
FileInputStream in = new FileInputStream("test.txt");
int b= 0;
while(true){
b = in.read();
if(b==-1){
break;
}
System.out.println(b);
}
}finally{
if(input!=null){
input.close();
}
}
}边栏推荐
- Opérations de lecture et d'écriture pour easyexcel
- Teach yourself to train pytorch model to Caffe (I)
- Get JS of the previous day (timestamp conversion)
- What should I do to prepare for the interview algorithm position during school recruitment?
- Monorepo management methodology and dependency security
- Deployment of Jenkins under win7
- [daily training] 729 My schedule I
- 張麗俊:穿透不確定性要靠四個“不變”
- Aitm 2-0003 horizontal combustion test
- Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
猜你喜欢

让开发效率飞速提升的跨端方案

Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)

leetcode:1755. Sum of subsequences closest to the target value

Five layer network protocol

Write an interface based on flask

Teach yourself to train pytorch model to Caffe (I)

Clickhouse copy paste multi line SQL statement error

Pytorch实战——MNIST数据集手写数字识别

Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance

Enclosed please find. Net Maui's latest learning resources
随机推荐
使用WebAssembly在浏览器端操作Excel
Opérations de lecture et d'écriture pour easyexcel
PVC plastic sheets BS 476-6 determination of flame propagation properties
Generics of TS
PostGIS installation geographic information extension
Monorepo management methodology and dependency security
Chapter 05_ Storage engine
int GetMonth( ) const throw( ); What does throw () mean?
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
php中explode函数存在的陷阱
Introduction to TS, constructor and its this, inheritance, abstract class and interface
浅聊我和一些编程语言的缘分
R语言【数据管理】
基于flask写一个接口
POJ 3414 pots (bfs+ clues)
ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图
Talk about my fate with some programming languages
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
MySQL deep paging optimization with tens of millions of data, and online failure is rejected!
The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application