欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java經(jīng)典問(wèn)題代碼,java中常見(jiàn)的問(wèn)題

java問(wèn)題,求寫出代碼

import?java.io.*;

在通州等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需求定制設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),全網(wǎng)整合營(yíng)銷推廣,外貿(mào)營(yíng)銷網(wǎng)站建設(shè),通州網(wǎng)站建設(shè)費(fèi)用合理。

import?java.util.Scanner;

public?class?Convert?{

public?static?void?main(String[]?args){

Scanner?scanner=new?Scanner(System.in);

System.out.println("請(qǐng)輸入要轉(zhuǎn)換文件所在的位置:");

String?inputPath=scanner.nextLine();

System.out.println("請(qǐng)輸入轉(zhuǎn)換后文件的路徑包括文件名:");

String?outputPath=scanner.nextLine();

File?inputFile=new?File(inputPath);

if(!inputFile.exists()){

System.out.println("要轉(zhuǎn)換的文件不存在!");

scanner.close();

return;

}

FileReader?fr=null;

BufferedReader?br=null;

FileWriter?fw=null;

PrintWriter?bw=null;

try{

fr=new?FileReader(inputFile);

br=new?BufferedReader(fr);

fw=new?FileWriter(outputPath);

bw=new?PrintWriter(fw);

while(true){

String?data=null;

data=br.readLine();

//文件讀完了,退出循環(huán)

if(data==null)

break;

bw.println(data.toUpperCase());

}

}catch(Exception?e){

e.printStackTrace();

}finally{

if(bw!=null)

bw.close();

if(fw!=null)

try?{fw.close();}?catch?(IOException?e)?{}

if(br!=null)

try?{br.close();}?catch?(IOException?e)?{}

if(fr!=null)

try?{fr.close();}?catch?(IOException?e)?{}

scanner.close();

}

}

}

java線程的經(jīng)典代碼

package threadgroup;

class ThreadDemo3 extends Thread {

private String name;

private int delay;

public ThreadDemo3(String sname, int i_delay) {

name = sname;

delay = i_delay;

}

public void run() {

try {

sleep(delay);

} catch (InterruptedException e) {

}

System.out.println("多線程測(cè)試!\n" + name + "\n" + delay);

}

}

public class testMyThread {

public static void main(String[] args) {

ThreadDemo3 th1,th2,th3;

th1 = new ThreadDemo3("線程1", (int) (Math.random() * 900));

th2 = new ThreadDemo3("線程2", (int) (Math.random() * 900));

th3 = new ThreadDemo3("線程3", (int) (Math.random() * 900));

th1.start();

th2.start();

th3.start();

}

}

package threadgroup;

public class threadDemo {

public static void main(String[] args) {

Thread t = Thread.currentThread();

t.setName("你好嗎?");

System.out.println("正在進(jìn)行的Thread是:" + t);

try {

for (int i = 0; i 5; i++) {

System.out.println("我不叫穆繼超" + i);

Thread.sleep(3000);

}

} catch (Exception e) {

// TODO: handle exception

System.out.println("Thread has wrong" + e.getMessage());

}

}

}

package threadgroup;

public class threadDemo2 implements Runnable {

public threadDemo2() {

Thread t1 = Thread.currentThread();

t1.setName("第一個(gè)主進(jìn)程");

System.out.println("正在運(yùn)行" + t1);

Thread t2 = new Thread(this, "");

System.out.println("在創(chuàng)建一個(gè)進(jìn)程");

t2.start();

try {

System.out.println("使他進(jìn)入第一個(gè)睡眠狀態(tài)");

Thread.sleep(2000);

} catch (InterruptedException e) {

System.out.println("Thread has wrong" + e.getMessage());

}

System.out.println("退出第一個(gè)進(jìn)程");

}

public void run() {

try {

for (int i = 0; i 5; i++) {

System.out.println("進(jìn)程" + i);

Thread.sleep(3000);

}

} catch (InterruptedException e) {

// TODO: handle exception

System.out.println("Thread has wrong" + e.getMessage());

}

System.out.println("退出第二個(gè)進(jìn)程");

}

public static void main(String[] args) {

new threadDemo2();

}

}

Java多線程經(jīng)典問(wèn)題!求代碼!最好給我思路

//銀行卡類

public class BanCard {

private Double money = 5000d;

public synchronized void drawMoney(double howMoney,String threadName){

try {

System.out.println(threadName+"進(jìn)入取錢操作!");

Thread.sleep(2000);//為了提前是一次只有一個(gè)線程進(jìn)入此方法,進(jìn)行了睡眠2秒

if(howMoneymoney){

System.out.println(threadName+"余額不足!");

return;

}

this.money-=howMoney;

System.out.println(threadName+"-原始余額:"+this.money+",取錢"+howMoney+"后,還剩余額"+this.money);

System.out.println(threadName+"結(jié)束取錢操作!");

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

//線程類

public class ThreadDemo implements Runnable {

private BanCard banCard = new BanCard();

private double howMoney=0d;

public void run() {

banCard.drawMoney(this.howMoney,Thread.currentThread().getName());

}

public double getHowMoney() {

return howMoney;

}

public void setHowMoney(double howMoney) {

this.howMoney = howMoney;

}

}

//main所在類

public class Test1 {

public static void main(String[] args) {

ThreadDemo threadDemo = new ThreadDemo();

threadDemo.setHowMoney(3000d);//取款3000

Thread thread1 = new Thread(threadDemo);

thread1.start();

threadDemo.setHowMoney(4000d);//取款4000

Thread thread2 = new Thread(threadDemo);

thread2.start();

}

}

一個(gè)很小的java問(wèn)題 代碼如下: enum Fruit { 蘋果,梨,香蕉,西瓜,芒果 }

這種情形大多是源文件里面還有其他類定義或者內(nèi)部類定義,然后編譯時(shí)會(huì)有xxx.class,xxx$1.class。其他情形暫未碰到。

JAVA多態(tài)經(jīng)典例題

System.out.println("1--" + a1.show(b));

a1是A類引用指向A類對(duì)象,不存在多態(tài),一定調(diào)用A類方法。A類方法有兩個(gè)show(D)和show(A),b是B類引用無(wú)法轉(zhuǎn)換為D類引用,但可以轉(zhuǎn)換為A類引用,因此調(diào)用show(A),輸出A and A。

System.out.println("2--" + a1.show(c));

輸出A and A,原因同上。

System.out.println("3--" + a1.show(d));

調(diào)用show(D),輸出A and D。

System.out.println("4--" + a2.show(b));

a2是A類引用指向B類對(duì)象,可能存在多態(tài)。b是B類引用無(wú)法轉(zhuǎn)換為D類引用,但可以轉(zhuǎn)換為A類引用,因此調(diào)用show(A),而B類重寫了show(A),因此調(diào)用的是重寫后的show(A),輸出B and A。

System.out.println("5--" + a2.show(c));

同上,C類引用無(wú)法轉(zhuǎn)換為D類引用,但可以轉(zhuǎn)換為A類引用,因此調(diào)用show(A),輸出B and A。

System.out.println("6--" + a2.show(d));

調(diào)用show(D),show(D)又調(diào)用父類即A類的show(D),輸出A and D

System.out.println("7--" + b.show(b));

b是B類引用指向B類對(duì)象,不存在多態(tài),一定調(diào)用B類方法。B類一共有三個(gè)方法:重寫自A類的show(A)和show(D),以及新定義的show(B)。show(b)調(diào)用show(B)方法,輸出B and B

System.out.println("8--" + b.show(c));

C類繼承自B類,也調(diào)用show(B)方法,輸出B and B

System.out.println("9--" + b.show(d));

調(diào)用show(D),show(D)又調(diào)用父類即A類的show(D),輸出A and D

當(dāng)前名稱:java經(jīng)典問(wèn)題代碼,java中常見(jiàn)的問(wèn)題
本文網(wǎng)址:http://chinadenli.net/article36/hegjsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站、企業(yè)網(wǎng)站制作電子商務(wù)、云服務(wù)器做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司