资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java综合实训改代码的简单介绍

java 代码改错,求指导2

将 deliverCard();//发牌

创新互联是一家专业提供金昌企业网站建设,专注与成都网站制作、网站建设、外贸网站建设H5页面制作、小程序制作等业务。10年已为金昌众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

repaint();

修改为

new Thread()

{

public void run()

{

deliverCard();//发牌

repaint();

}

}

.start();

不过你的dowhile是个死循环 症结在这里

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中如何更改以下代码实现指定数据的替换求大神帮助

这段代码只能替换第一个oldStr,并且这个oldStr只能作为一行出现。不知道你想修改成什么样的,是要修改成一行当中的某个字符串吗?还是什么。。。 如果这个oldStr并不是一行的话,你可以用StringTokenizer tokenizer = new StringTokenizer(line, oldStr);的方法来找到匹配的oldStr,然后对其进行替换。如果需要替换全部的oldStr,你可以这样做 while(temp = br.readLine()) != null ) { //逐行查找替换。用StringTokenizer } 更加简单的方法就是,直接读出文件,放到String中,用replaceAll的方法就可以替换所有的,用replaceFirst就能只替换第一个。

这是我们的java实训内容,有没有大神知道其中的代码怎么打?知道几条也行,谢谢了! 2、 能新

2,3已经实现,其他的自己试着做一下不难

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{

//创建文件

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代码修改 高分求解

把这一段放在一个循环里,然后判断是否继续输入的值,如果继续,那就继续下一次循环,如果停止,则跳出循环

计算次数放在小循环里,每输入一次加1,在大循环里定义,每次大循环都会从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;

}

}

}


本文题目:java综合实训改代码的简单介绍
当前路径:http://cdkjz.cn/article/dosdgoo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220