1、 编写一个程序Java1,定义书Book类:
1)、包含成员变量:书名称(name),作者(author)、出版社(publisher)、定价(price), 并设置为private
2)、编写public的无参数和有参数构造函数
3)、编写public的显示函数show()
4)、在main函数中产生Book的对象,用show显示2、编写一个程序Java2,输入一个文本文件的名称,显示出该文件的内容。3、编写一个程序Java3,输入一个字符串,统计出各个字母'A'-'Z'(不分大小写)分别出现的次数,显示输出。
提示输入字符串:
import java.io.*;
......
BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a line:");
System.out.println(stdin.readLine());
1)、包含成员变量:书名称(name),作者(author)、出版社(publisher)、定价(price), 并设置为private
2)、编写public的无参数和有参数构造函数
3)、编写public的显示函数show()
4)、在main函数中产生Book的对象,用show显示2、编写一个程序Java2,输入一个文本文件的名称,显示出该文件的内容。3、编写一个程序Java3,输入一个字符串,统计出各个字母'A'-'Z'(不分大小写)分别出现的次数,显示输出。
提示输入字符串:
import java.io.*;
......
BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a line:");
System.out.println(stdin.readLine());
认识的在QQ问过我!
但是我在高C/C++帮不了你,所以叫他上这里问 呵呵!
{
public static void main(String[] args)
{
Book[] b={new Book(),new Book("book1","zhangshan","Sun",99)};
for(Book a:b)
a.show();
}
}
class Book
{
public Book()
{
name="Core Java 2";
author="Gary cornell";
publisher="Sun";
price=88.00;
}
public Book(String name,String author,String publisher,double price)
{
this.name=name;
this.author=author;
this.publisher=publisher;
this.price=price;
}
public void show()
{
System.out.println("The book name is "+name+", author is "+author+" ,publisher is "+publisher+" ,price is "+price);
}
private String name;
private String author;
private String publisher;
private double price;
}
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;public class Exercise2
{
public static void main(String[] args) throws IOException
{
Scanner in=new Scanner(System.in);
String filename;
if(args.length>0)
{
filename=args[0];
}
else
{
System.out.println("请输入文件绝对路径");
filename=in.next();
}
if(filename==null || filename.equals(""))
{
System.out.println("请输入文件绝对路径???");
}
else
{
new Exercise2().readFile(filename);
}
}
public void readFile(String filename) throws IOException
{
FileInputStream fis=new FileInputStream(filename);
byte[] buf=new byte[10000];
int len=fis.read(buf);
System.out.println(new String(buf,0,len));
}
}
public class Exercise3
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("输入个字符串");
String s=in.next();
char[] c=s.toCharArray();
System.out.println(c);
new Exercise3().printChar(c);
}
public void printChar(char[] line)
{
char[] ch=new char[line.length];
int[] counter=new int[line.length];
int flag=0;
for(int i=0;i<line.length;i++)
{
boolean b=false;
for(int j=0;j<=i;j++)
{
if(ch[j]==line[i])
{
counter[j]++;
b=true;
continue;
}
}
if(!b)
{
ch[flag]=line[i];
counter[flag]++;
flag++;
}
}
String s=new String(line);
System.out.println("你输入的字符串是:"+ s+" 其中:" );
for(int i=0;i<ch.length;i++)
{
if(ch[i]!=0)
System.out.println(ch[i]+" 出现了 "+counter[i]+" 次");
}
}
}
要不说“小女子”可能还好些。
虽然我也是菜鸟,但还是看不惯这样作业都要别人帮做的,以后出来,工作上的项目也要别人帮着做?不过现在这样的人还真不少?刚在别的论坛也才遇到过一个。http://bbs.blueidea.com/thread-2760765-1-1.html
就应该帮他啊,不应该看问题片面
管她性别什么事啊
phoenixzong() 热心人....
String name,author,publisher;
private double price;
public Book() {
}
public Book(String name,String author,String publisher,double price) {
this.name=name;
this.author=author;
this.publisher=publisher;
this.price=price;
}
String GetName(){
return name;
}
String GetAuthor(){
return author;
}
String GetPublisher(){
return publisher;
}
double GetPrice(){
return price;
}
public void show(){
System.out.print(GetName()+" "+GetAuthor()+ " "+GetPublisher()+" "+GetPrice());
}
public static void main(String[] args){
Book f=new Book("左手年华","小郭","春风出版社",23);
f.show();
}
}
我写一个,初学,写的没他们好哈.......
忘了说了,第二题关于io我还没学到,看API做的,可能经不住测试,第三题把char[] ch=s.toCharArray() 改成char[] c=s.toLowerCase().toCharArray();就不区分大小写了。
第一题
Public class a {
Public class book
{
Private String name;
Private String author;
Private String publisher;
Private float price;
public Book()
{
name="think in java";
author=" ";
publisher="Sun";
price=120;
}
public Book(String name,String author,String publisher,float price)
{
this.name=name;
this.author=author;
this.publisher=publisher;
this.price=price;
}
Public void show()
{
System.out.println(“book name is ”+name);
System.out.println(“book author is ”+ author);
System.out.println(“book price is ”+ price);}
}
public static void main(String[] args)
{
Book book1=new book();
Book1.show();
}
}
解决这种问题的人
一个字:贱
package homework;public class Book {
String n; String a; String p; double d; private void book(String name, String auther, String publisher, double price) {
n = name;
a = auther;
p = publisher;
d = price; } void show() {
System.out.println("书名是:" + n);
System.out.println("作者:" + a);
System.out.println("出版社:"+p);
System.out.println("价钱:" + d); }
public static void main(String[] args) {
Book test=new Book();
test.book("人妖", "我", "北京", 25.3);
test.show();
}}