当前位置:网站首页>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();
}
}
}
边栏推荐
- Selenium gets the verification code image in DOM
- Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
- Selenium finds the contents of B or P Tags
- Cross end solution to improve development efficiency rapidly
- js常用方法封装
- 显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
- Monorepo management methodology and dependency security
- WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
- Deployment of Jenkins under win7
- 浅聊我和一些编程语言的缘分
猜你喜欢
学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
PVC 塑料片BS 476-6 火焰传播性能测定
ArcGIS栅格重采样方法介绍
冯唐“春风十里不如你”数字藏品,7月8日登录希壤!
让开发效率飞速提升的跨端方案
Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»
[case] Application of positioning - Taobao rotation map
Clickhouse copy paste multi line SQL statement error
Golang (1) | from environmental preparation to quick start
2022-07-03-cka- latest feedback from fans
随机推荐
思特奇加入openGauss开源社区,共同推动数据库产业生态发展
Objects in the list, sorted by a field
CLion配置visual studio(msvc)和JOM多核编译
MQ----activeMq
PVC 塑料片BS 476-6 火焰传播性能测定
LeetCode: Distinct Subsequences [115]
Simple interest mode - evil Chinese style
[case] Application of positioning - Taobao rotation map
js常用方法封装
Enclosed please find. Net Maui's latest learning resources
R语言【数据管理】
[daily training] 729 My schedule I
Binary search
Sequence alignment
PHP deserialization +md5 collision
ArcGIS栅格重采样方法介绍
leetcode:1755. Sum of subsequences closest to the target value
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
Display DIN 4102-1 Class B1 fire test requirements
秋招将临 如何准备算法面试、回答算法面试题