当前位置:网站首页>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();
}
}
}
边栏推荐
- Simple interest mode - evil Chinese style
- 2022-07-03-cka- latest feedback from fans
- Wood board ISO 5660-1 heat release rate mapping test
- Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
- 木板ISO 5660-1 热量释放速率摸底测试
- Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
- 第05章_存储引擎
- vant 源码解析之 utils/index.ts 工具函数
- Monorepo management methodology and dependency security
- 学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
猜你喜欢
Enclosed please find. Net Maui's latest learning resources
Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»
Pytoch practice -- MNIST dataset handwritten digit recognition
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
JMeter installation under win7
ArcGIS栅格重采样方法介绍
ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图
張麗俊:穿透不確定性要靠四個“不變”
Display DIN 4102-1 Class B1 fire test requirements
【案例】定位的运用-淘宝轮播图
随机推荐
Influence of oscilloscope probe on signal source impedance
Reading and writing operations of easyexcel
Selenium finds the contents of B or P Tags
Sophomore personal development summary
面试官:并发编程实战会吗?(线程控制操作详解)
Pytorch实战——MNIST数据集手写数字识别
事项研发工作流全面优化|Erda 2.2 版本如“七”而至
判断横竖屏的最佳实现
Modifiers of attributes of TS public, private, protect
Influence of oscilloscope probe on measurement bandwidth
2022-07-03-CKA-粉丝反馈最新情况
Write an interface based on flask
让开发效率飞速提升的跨端方案
Wood board ISO 5660-1 heat release rate mapping test
Add ICO icon to clion MinGW compiled EXE file
張麗俊:穿透不確定性要靠四個“不變”
Simple interest mode - lazy type
Dictionary tree simple introductory question (actually blue question?)
How to send samples when applying for BS 476-7 display? Is it the same as the display??
字典树简单入门题(居然是蓝题?)