《java源程序.doc》由会员分享,可在线阅读,更多相关《java源程序.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、package com.wsy;public class cricle public static void main(String args)System.out.println(hello world);public class Fruit public String color;public Fruit()color =绿色;public void harvest()String color = 红色;System.out.println(水果是:+color+的!);System.out.println(水果已经收获。);System.out.println(水果原来是:+this.c
2、olor+的!);public static void main(String args)Fruit fruit = new Fruit();fruit.harvest();水果是:红色的!水果已经收获。水果原来是:绿色的!public class Circ final float PI = 3.14159f;public float r = 0.0f;public float getArea()float area = PI*r*r;return area;public float getCircumference(float r)float circumference = 2*PI*r;r
3、eturn circumference;public static void main(String args)Circ circ = new Circ();circ.r = 20;float r = 20;float area = circ.getArea();System.out.println(圆的面积为:+area);float circumference = circ.getCircumference(r);System.out.println(圆的周长为:+circumference);圆的面积为:1256.636圆的周长为:125.663605public class Anima
4、l public boolean live = true;public String skin = ;public void eat()System.out.println(动物需要吃东西);public void move()System.out.println(动物会运动);public class Bird extends Animalpublic String skin = 羽毛;public void move()System.out.println(鸟会飞翔);public class Zoo public static void main(String args)Bird bir
5、d = new Bird();bird.eat();bird.move();System.out.println(鸟有:+bird.skin);动物需要吃东西鸟会飞翔鸟有:羽毛/从控制台获取用户输入的字符串信息import java.io.*;public class InputStreamGetStr public static void main(String args)InputStream is = System.in;trybyte bs = new byte50;int i = is.read(bs);/用于诵读输入的字符串所占用的字节数(再加2(这个点不懂)System.out.
6、println(控制台输入的内容:+new String(bs).trim();System.out.println(i);is.close();catch(IOException e)e.printStackTrace();/如何通过OutputStream类向控制台输出字符串信息import java.io.*;public class OutPutStreamWriteStr public static void main(String args)OutputStream out = System.out;trybyte bs = 本例使用OutputStream输出流,在控制台输出字符串n.getBytes();out.write(bs);bs = 输出内容:n.getBytes();out.write(bs);bs = 明日科技有限公司.getBytes();out.write(bs);out.close();catch(IOException e)e.printStackTrace();