java綜合實訓改代碼的簡單介紹

java 代碼改錯,求指導2

將 deliverCard();//發(fā)牌

創(chuàng)新互聯(lián)是一家專業(yè)提供金昌企業(yè)網(wǎng)站建設,專注與成都網(wǎng)站制作、網(wǎng)站建設、外貿(mào)網(wǎng)站建設、H5頁面制作、小程序制作等業(yè)務。10年已為金昌眾多企業(yè)、政府機構等服務。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進行中。

repaint();

修改為

new Thread()

{

public void run()

{

deliverCard();//發(fā)牌

repaint();

}

}

.start();

不過你的dowhile是個死循環(huán) 癥結(jié)在這里

java 編程 修改下面的代碼 要求顯示小明的年齡是15,成績是92.5

package?demo19;

class?Student?{

private?String?name;

private?int?age;

private?float?score;

public?String?getName()?{

return?name;

}

public?void?setName(String?name)?{

this.name?=?name;

}

public?int?getAge()?{

return?age;

}

public?void?setAge(int?age)?{

this.age?=?age;

}

public?float?getScore()?{

return?score;

}

public?void?setScore(float?score)?{

this.score?=?score;

}

public?void?say()?{

System.out.println(this.name?+?"的年齡是"?+?this.age?+?",成績是"?+?this.score);

}

}

public?class?HelloWorld?{

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

Student?student?=?new?Student();

student.setName("小明");

student.setAge(15);

student.setScore(92.5f);

student.say();

}

}

在java中如何更改以下代碼實現(xiàn)指定數(shù)據(jù)的替換求大神幫助

這段代碼只能替換第一個oldStr,并且這個oldStr只能作為一行出現(xiàn)。不知道你想修改成什么樣的,是要修改成一行當中的某個字符串嗎?還是什么。。。 如果這個oldStr并不是一行的話,你可以用StringTokenizer tokenizer = new StringTokenizer(line, oldStr);的方法來找到匹配的oldStr,然后對其進行替換。如果需要替換全部的oldStr,你可以這樣做 while(temp = br.readLine()) != null ) { //逐行查找替換。用StringTokenizer } 更加簡單的方法就是,直接讀出文件,放到String中,用replaceAll的方法就可以替換所有的,用replaceFirst就能只替換第一個。

這是我們的java實訓內(nèi)容,有沒有大神知道其中的代碼怎么打?知道幾條也行,謝謝了! 2、?能新

2,3已經(jīng)實現(xiàn),其他的自己試著做一下不難

package com.ui;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

class NoteBook{

//創(chuàng)建文件

public File creatFile(String path,String name){

File tempPath=new File(path);

File tempFile=new File(path+File.separator+name+".txt");

if(!tempPath.exists()){

tempPath.mkdirs();

try {

tempFile.createNewFile();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}else{

try {

tempFile.createNewFile();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

return tempFile;

}

//寫入文件

public void writeFile(File file,String content){

try {

FileOutputStream fos=new FileOutputStream(file);

fos.write(content.getBytes());

fos.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

//讀取文件

public String readFile(File file){

String str="";

try {

FileInputStream fis=new FileInputStream(file);

int datas;

while((datas=fis.read())!=-1){

str+=String.valueOf((char)datas);

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return str;

}

//復制文件

public ?void copyFile(File f1,File f2){

if(!f1.exists()){

System.out.println("目錄"+f1.getName()+"不存在");

}else{

File[] files=f1.listFiles();

for(File f:files){

if(f.isDirectory()){

File temp=new File(f2,f.getName());

temp.mkdirs();

copyFile(f, temp);

}else{

File temp=new File(f2,f.getName());

try {

temp.createNewFile();

FileOutputStream fos=new FileOutputStream(temp);

FileInputStream fis=new FileInputStream(f);

int datas;

while((datas=fis.read())!=-1){

fos.write(datas);

}

fos.close();

fis.close();

} catch (FileNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

}

//剪貼文件

public void cutFile(File f1,File f2){

int i=0;

if(!f1.exists()){

System.out.println("目錄"+f1.getName()+"不存在");

}else{

i++;

File[] files=f1.listFiles();

for(File f:files){

if(f.isDirectory()){

File temp=new File(f2,f.getName());

temp.mkdirs();

cutFile(f, temp);

}else{

File temp=new File(f2,f.getName());

try {

temp.createNewFile();

FileOutputStream fos=new FileOutputStream(temp);

FileInputStream fis=new FileInputStream(f);

int datas;

while((datas=fis.read())!=-1){

fos.write(datas);

}

fis.close();

fos.close();

f.delete();

} catch (FileNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

f1.delete();

}

}

java代碼修改 高分求解

把這一段放在一個循環(huán)里,然后判斷是否繼續(xù)輸入的值,如果繼續(xù),那就繼續(xù)下一次循環(huán),如果停止,則跳出循環(huán)

計算次數(shù)放在小循環(huán)里,每輸入一次加1,在大循環(huán)里定義,每次大循環(huán)都會從0開始

while(true){

int count = 0;

int number = rand.nextInt(100);

System.out.print("Your guess?");

int guess = console.nextInt();

do{

if (guess number){

count++;

System.out.println("It's lower.");

System.out.print("Your guess?");

guess = console.nextInt();

i++;

}else if (guess number){

System.out.println("It's higher.");

System.out.print("Your guess?");

guess = console.nextInt();

i++;

}

}while(guess != number);

if(guess == number){

System.out.println("You got it right in " + i + " guesses!");

System.out.println("Do you want to play again?");

String line = console.nextLine();

if (line.startsWith("Y")||line.startsWith("y")) {

guess();

}else if (line.startsWith("N")||line.startsWith("n")) {

break;

}

}

}

網(wǎng)頁名稱:java綜合實訓改代碼的簡單介紹
網(wǎng)頁鏈接:http://muchs.cn/article0/dosdgoo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設計、軟件開發(fā)、ChatGPT、關鍵詞優(yōu)化定制網(wǎng)站、網(wǎng)站策劃

廣告

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

搜索引擎優(yōu)化