真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

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

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

import?java.io.*;

在通州等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專(zhuān)注、極致的服務(wù)理念,為客戶(hù)提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需求定制設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),全網(wǎng)整合營(yíng)銷(xiāo)推廣,外貿(mào)營(yíng)銷(xiāo)網(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線(xiàn)程的經(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("多線(xiàn)程測(cè)試!\n" + name + "\n" + delay);

}

}

public class testMyThread {

public static void main(String[] args) {

ThreadDemo3 th1,th2,th3;

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

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

th3 = new ThreadDemo3("線(xiàn)程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多線(xiàn)程經(jīng)典問(wèn)題!求代碼!最好給我思路

//銀行卡類(lèi)

public class BanCard {

private Double money = 5000d;

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

try {

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

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

if(howMoneymoney){

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

return;

}

this.money-=howMoney;

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

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

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

//線(xiàn)程類(lèi)

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所在類(lèi)

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 { 蘋(píng)果,梨,香蕉,西瓜,芒果 }

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

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

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

a1是A類(lèi)引用指向A類(lèi)對(duì)象,不存在多態(tài),一定調(diào)用A類(lèi)方法。A類(lèi)方法有兩個(gè)show(D)和show(A),b是B類(lèi)引用無(wú)法轉(zhuǎn)換為D類(lèi)引用,但可以轉(zhuǎn)換為A類(lèi)引用,因此調(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類(lèi)引用指向B類(lèi)對(duì)象,可能存在多態(tài)。b是B類(lèi)引用無(wú)法轉(zhuǎn)換為D類(lèi)引用,但可以轉(zhuǎn)換為A類(lèi)引用,因此調(diào)用show(A),而B(niǎo)類(lèi)重寫(xiě)了show(A),因此調(diào)用的是重寫(xiě)后的show(A),輸出B and A。

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

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

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

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

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

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

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

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

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

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


本文題目:java經(jīng)典問(wèn)題代碼,java中常見(jiàn)的問(wèn)題
分享鏈接:http://weahome.cn/article/hegjsg.html

其他資訊

在線(xiàn)咨詢(xún)

微信咨詢(xún)

電話(huà)咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部