当前位置:网站首页>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();
}
}
}
边栏推荐
- SQL series (basic) - Chapter 2 limiting and sorting data
- Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
- Mode - "Richter replacement principle"
- [case] Application of positioning - Taobao rotation map
- MQ----activeMq
- Comprehensive optimization of event R & D workflow | Erda version 2.2 comes as "7"
- Realize the function of verifying whether the user has completed login when browsing the page
- PHP deserialization +md5 collision
- How to send samples when applying for BS 476-7 display? Is it the same as the display??
- Talk about my fate with some programming languages
猜你喜欢
ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
How to send samples when applying for BS 476-7 display? Is it the same as the display??
【案例】定位的运用-淘宝轮播图
Simple interest mode - evil Chinese style
Influence of oscilloscope probe on measurement bandwidth
Teach yourself to train pytorch model to Caffe (I)
Parker驱动器维修COMPAX控制器维修CPX0200H
Golang(1)|从环境准备到快速上手
Comprehensive optimization of event R & D workflow | Erda version 2.2 comes as "7"
随机推荐
Teach yourself to train pytorch model to Caffe (2)
Écrire une interface basée sur flask
LeetCode_哈希表_困难_149. 直线上最多的点数
Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
JS common method encapsulation
PVC 塑料片BS 476-6 火焰传播性能测定
SYSTEMd resolved enable debug log
Selenium gets the verification code image in DOM
MySQL 千万数据量深分页优化, 拒绝线上故障!
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
MQ----activeMq
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
Postgres establish connection and delete records
Talk about my fate with some programming languages
股票开户选择哪家证券公司比较好哪家平台更安全
Hdu2377bus pass (build more complex diagram +spfa)
判断横竖屏的最佳实现
Introduction of ArcGIS grid resampling method
树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因