程序改错题,请指出指定位置语句的错误。
Class Book{ //6:
public String name;
private float price;
initBook(String n,float p){ //1:
name=n;price=p;}
public void setPrice(float p){
this.price=p } //2:public class useBook{
public void main(String arg[]){
Book b=new Book(“Java2”,52.5f); //3:
System.out.print(“name”+name); //4:
System.out.print(“\tprice:”+price); //5:
} //12:
编程题
定义一个时钟类—Clock,它包括三个整型变量分别表示小时、分钟和秒,一个成员方法show()用于显示时钟对象的时间信息(显示格式:”时间为15:20:35”)。定义描述学生的类—Student,成员变量:学生姓名(name)、年龄(age) 和学生编号(整数型,静态成员);output成员方法用于输出学生信息(信息格式:“编号:1,姓名:张山,年龄:25”),构造方法初始化3个成员变量。如:Student s1=new Student(“张山”,25)
谢谢各位,我是菜鸟。
Class Book{ //6:
public String name;
private float price;
initBook(String n,float p){ //1:
name=n;price=p;}
public void setPrice(float p){
this.price=p } //2:public class useBook{
public void main(String arg[]){
Book b=new Book(“Java2”,52.5f); //3:
System.out.print(“name”+name); //4:
System.out.print(“\tprice:”+price); //5:
} //12:
编程题
定义一个时钟类—Clock,它包括三个整型变量分别表示小时、分钟和秒,一个成员方法show()用于显示时钟对象的时间信息(显示格式:”时间为15:20:35”)。定义描述学生的类—Student,成员变量:学生姓名(name)、年龄(age) 和学生编号(整数型,静态成员);output成员方法用于输出学生信息(信息格式:“编号:1,姓名:张山,年龄:25”),构造方法初始化3个成员变量。如:Student s1=new Student(“张山”,25)
谢谢各位,我是菜鸟。
解决方案 »
- 向高手请教。。。
- 请教一段java正则表达式代码,就是根据公式计算结果
- Java中Iterator在递归函数中的问题
- [一道笔试题。小弟实在没分可送了]关于有父子类继承关系时类及对象初始化时机的问题
- 用HtmlParser解析网页中文乱码问题
- 在java如何判断字符串有多少中文字?(在线等)
- super!?
- 内急,如何将oracle中存放的图片(如Blob类类型的字段)还原成一副图片.
- 新手,急需一个带输入、出参数的存储过程的例子(oracle)的
- 请问这个bean什么地方错了?
- 求原代码,立即结贴:读一个文件夹中所有文件,并得到所有文件总行数,文件名未知。
- 关于Applet与servlet通讯问题,高手请进,在线等!
//1 应为Book(X,X)把init去掉
//2 少分号
//3 去f
//4 b.name
//5 price为私有变量
//12 少分号
class Book
{
public String name;
public float price;
Book(String n,float p)
{
name=n;price=p;
}
public void setPrice(float p)
{
this.price=p;
}
}public class useBook
{
public static void main(String arg[])
{
Book b=new Book("Java2",52.5f);
System.out.print("name"+b.name);
System.out.print("\tprice:"+b.price);
}
}
public class Clock {
private int h; private int m; private int s; public Clock(int h, int m, int s) {
this.h = h;
this.m = m;
this.s = s;
} public void show() {
System.out.println("时间为" + h + ":" + m + ":" + s);
} public static void main(String[] arge) {
Clock clock = new Clock(12, 45, 20);
clock.show();
}
}
Student那个和这个差不多替换参数和方法名就可以
/* 定义描述学生的类—Student,成员变量:学生姓名(name)、年龄(age) 和学生编号(整数, 静态成员);output成员方法用于输出学生信息(信息格式:“编号:1,姓名:张山,年龄:25”),构造方法初始化3个成员变量。如:Student s1=new Student(“张山”,25)
*/public class Student {
private String name; private int age; private static int No = 1; public Student(String name, int age) {
this.name = name;
this.age = age;
this.No++;
} public void output() {
System.out.println("编号:" + No + "姓名:" + name + "年龄:" + age);
} public static void main(String[] arge) {
Student s1=new Student(“张山”,25);
s1.output();
}
} 不知道行不行,照着楼上的大哥的代码写的,我也是新手,一起学习,楼下的,不对的地方给我说声阿,先谢谢了