class HelloWorld{
public static void main(String [] arguments) {
System.out.println("Hello World!");
System.out.println("Test Successly!");
}
}

简单的java测试

class MyFirstApp {
public static void main (String[] args) {
System.out.println("I Rule");
System.out.println("The World");
}
}
class Loopy {
public static void main (String[] args) {
int x=1;
System.out.println("Before the Loop");
while(x < 4) {
System.out.println("In the Loop");
System.out.println("Value of x is " + x);
x = x + 1;
}
System.out.println("This is after the Loop");
}
}

简单if语句的测试

class IfTest {
public static void main (String [] args) {
int x = 3;
if(x==3) {
System.out.println("x must be 3");
}
System.out.println("This runs no matter what");
}
}
class IfTest2 {
public static void main (String[] args) {
int x = 2;
if (x == 3) {
System.out.println ("x must be 3");
} else {
System.out.println("x is NOT 3");
}
System.out.println("This runs no matter what");
}
}
class PhraseCMatic {
public static void main(String[] args) {
String[] wordListOne = {"24/7", "multiTier", "30,000", "B-to-B", "win-win", "front-end", "web-based", "pervasive", "smart", "six-sigma", "critical-path", "dynamic"};
String[] wordListTwo = {"empoweres", "sticky", "value-added", "oriented", "centric", "distributed", "clustered", "branded", "outside-the-box", "positioned", "networked", "focused", "leveraged", "aligned", "targeted", "shared", "cooperatived", "accelerated"};
String[] wordListThree = {"process", "tipping", "point", "solution", "architecture", "core competency", "strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission"};
int oneLength = wordListOne.length;
int twoLength = wordListTwo.length;
int threeLength = wordListThree.length; int rand1 = (int) (Math.random() * oneLength);
int rand2 = (int) (Math.random() * twoLength);
int rand3 = (int) (Math.random() * threeLength); String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
System.out.println("What we need is a " + phrase);
}
}
class BeerSong {
public static void main(String[] args) {
int beerNum = 99;
String word = "bottles";
while(beerNum > 0) {
if(beerNum == 1) {
word = "bottle";
}
System.out.println(beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + word + " of beer.");
System.out.println("Take one down");
System.out.println("Pass it around");
beerNum = beerNum - 1;
// if(beerNum > 0)
// System.out.println(beerNum + " " + word + " of beer on the wall");
// else {
// System.out.println("No more bottles of beer on the wall");
// }
if(beerNum <= 0)
{
System.out.println("No more bottles of beer on the wall" );
}
}
}
}
class Shuffel {
public static void main(String[] args) {
int x = 3;
while (x > 0) {
if(x == 1) {
System.out.print("d");
x = x - 1;
}
if(x == 2) {
System.out.print("b c");
}
if(x > 2) {
System.out.print("a");
}
x = x - 1;
System.out.print("-");
}
}
}
class Test {
public static void main(String[] args) {
int x = 0;
int y = 0;
while (x < 5) {
y = x - y;
y = y + x;
System.out.print(x + " " + y + " ");
x = x + 1;
}
}
}
class PoolPuzzleOne {
public static void main (String[] args) {
int x = 0;
while (x < 4) {
System.out.print("a");
if(x < 1) {
System.out.print(" ");
}
System.out.print("n");
if(x > 1) {
System.out.print("oyster");
x = x + 2;
}
if(x == 1) {
System.out.print("noys");
}
if(x < 1) {
System.out.print("oise");
}
System.out.println(" ");
x = x + 1;
}
}
}
class Dog {
int size;
String breed;
String name; void bark() {
System.out.println("Ruff! Ruff!");
}
} class DogTestDrive {
public static void main(String[] args) {
Dog d = new Dog();
d.size = 40;
d.bark();
}
}
class Movie {
String title;
String genre;
int rating;
void playIt() {
System.out.println("Playing the movie");
}
} class MovieTestDrive {
public static void main (String[] aargs) {
Movie one = new Movie();
one.title = "Gone with the Stock";
one.rating = -2;
Movie two = new Movie();
two.genre = "Comedy";
two.rating = 5;
two.playIt();
Movie three = new Movie();
three.title = "Byte Club";
three.genre = "Tragic but ultimately uplifting";
three.rating = 127;
}
}
// 猜字游戏
class GuessGame {
Player p1;
Player p2;
Player p3; public void startGame() {
p1 = new Player();
p2 = new Player();
p3 = new Player(); int guessp1 = 0;
int guessp2 = 0;
int guessp3 = 0; boolean p1isRight = false;
boolean p2isRight = false;
boolean p3isRight = false; int targetNumber = (int) (Math.random() * 10);
System.out.println("I'm thinging of a number between o and 9..."); while(true) {
System.out.println("Number to guess is " + targetNumber); p1.guess();
p2.guess();
p3.guess(); guessp1 = p1.number;
System.out.println("Flayer one guessed " + guessp1); guessp2 = p2.number;
System.out.println("Flayer two guessed " + guessp2); guessp3 = p3.number;
System.out.println("Flayer three guessed " + guessp3); if(guessp1 == targetNumber) {
p1isRight = true;
} if(guessp2 == targetNumber) {
p2isRight = true;
} if(guessp3 == targetNumber) {
p3isRight = true;
} if(p1isRight || p2isRight || p3isRight) {
System.out.println("We have a winner!");
System.out.println("Player one got it right? " + p1isRight);
System.out.println("Player two got it right? " + p2isRight);
System.out.println("Player three got it right? " + p3isRight);
System.out.println("Game is over.");
break;
}
else {
System.out.println("Player will have to try again.");
}
}
}
} class Player {
int number = 0;
public void guess() {
number = (int) (Math.random() * 10);
System.out.println("I'm guessing " + number);
}
} class GameLauncher {
public static void main(String[] args) {
GuessGame game = new GuessGame();
game.startGame();
}
}
class DrumKit {
boolean topHat = true;
boolean snare = true; void playTopHat() {
System.out.println("ding ding da-ding");
} void playSnare() {
System.out.println("bang bang ba-bang");
}
} class DrumKitTestDrive {
public static void main(String[] args) {
DrumKit d = new DrumKit();
d.playSnare();
d.snare = false;
d.playTopHat(); if(d.snare == true) {
d.playSnare();
}
}
}
class TapeDeck {
boolean canRecord = false;
void playTape() {
System.out.println("tape playing");
} void recordTape() {
System.out.println("tape recording");
}
} class TapeDeckTestDrive {
public static void main(String[] args) {
TapeDeck t = new TapeDeck();
t.canRecord = true;
t.playTape(); if(t.canRecord == true) {
t.recordTape();
}
}
} class DVDPlayer {
boolean canRecord = false;
void recordDVD() {
System.out.println("DVD recording");
} void playDVD() {
System.out.println("DVD playing");
}
} class DVDPlayerTestDrive {
public static void main(String[] args) {
DVDPlayer d = new DVDPlayer();
d.canRecord = true;
d.playDVD();
if(d.canRecord == true) {
d.recordDVD();
}
}
}
class Echo {
int count = 0;
void hello() {
System.out.println("helloooo...");
}
} class EchoTestDrive {
public static void main(String[] args) {
Echo e1 = new Echo();
Echo e2 = new Echo();
int x = 0;
while(x < 4) {
e1.hello();
e1.count = e1.count + 1;
if(x == 3) {
e2.count = e2.count + 1;
}
if(x > 0) {
e2.count = e2.count + e1.count;
}
x = x + 1;
}
System.out.println(e2.count);
}
}
class Dog {
String name;
public static void main (String[] args) {
Dog dog1 = new Dog();
dog1.bark();
dog1.name = "Bart"; Dog[] myDogs = new Dog[3]; myDogs[0] = new Dog();
myDogs[1] = new Dog();
myDogs[2] = dog1; myDogs[0].name = "Fred";
myDogs[1].name = "Marge"; System.out.print("last dog's name is ");
System.out.println(myDogs[2].name); int x = 0;
while(x < myDogs.length) {
myDogs[x].bark();
x = x + 1;
}
}
public void bark() {
System.out.println(name + " says Ruff!");
} public void eat() {
}
public void chaseCat() {
}
}
class TestArrays {
public static void main(String[] args) {
int [] index = new int[4];
index[0] = 1;
index[1] = 3;
index[2] = 0;
index[3] = 2; String[] islands = new String[4]; islands[0] = "Bermuda";
islands[1] = "Fiji";
islands[2] = "Azores";
islands[3] = "Cozumel"; int y = 0;
int ref; while(y < 4) {
ref = index[y];
System.out.print("island = ");
System.out.println(islands[ref]);
y = y + 1;
}
}
}
class Books {
String title;
String author;
} class BooksTestDrive {
public static void main (String[] args) {
Books [] myBooks = new Books[3];
int x = 0; myBooks[0] = new Books();
myBooks[1] = new Books();
myBooks[2] = new Books(); myBooks[0].title = "The Grapes of java ";
myBooks[1].title = "The Java Gatsby ";
myBooks[2].title = "The Java Cookbook ";
myBooks[0].author = "bob";
myBooks[1].author = "sue";
myBooks[2].author = "lan"; while(x < 3) {
System.out.print(myBooks[x].title);
System.out.print(" by ");
System.out.println(myBooks[x].author);
x = x + 1;
}
}
}
class Hobbits {
String name;
public static void main(String[] args) {
Hobbits[] h = new Hobbits[3];
int z = -1;
while(z < 2) {
z = z + 1;
h[z] = new Hobbits();
h[z].name = "bilbo";
if(z == 1) {
h[z].name = "frodo";
}
if(z == 2) {
h[z].name = "sam";
}
System.out.print(h[z].name + " is a ");
System.out.println("good hobbit name");
}
}
}
class Triangle {
double area;
int height;
int length;
public static void main(String[] args) {
int x = 0;
Triangle [] ta = new Triangle[4];
while(x < 4) {
ta[x] = new Triangle();
ta[x].height = (x + 1) * 2;
ta[x].length = x + 4;
ta[x].setArea();
System.out.print("triangle " + x + ", area ");
System.out.println(" = " + ta[x].area);
x = x + 1;
}
int y = x;
x = 27;
Triangle t5 = ta[2];
ta[2].area = 343;
System.out.print("y = " + y);
System.out.println(", t5 area = " + t5.area);
}
void setArea() {
area = (height * length) / 2;
}
}
class Dog {
int size;
String name; void bark() {
if(size > 60) {
System.out.println("Wooof! Wooof!");
} else if(size > 14) {
System.out.println("Ruff! Ruff!");
} else {
System.out.println("Yip! Yip!");
}
}
} class DogTestDrive {
public static void main(String[] args) {
Dog one = new Dog();
one.size = 70;
Dog two = new Dog();
two.size = 8;
Dog three = new Dog();
three.size = 35;
one.bark();
two.bark();
three.bark();
}
}
class GoodDog {
private int size;
public int getSize() {
return size;
} public void setSize(int s) {
size = s;
} void bark() {
if(size > 60) {
System.out.println("Wooof! Wooof!");
} else if(size > 14) {
System.out.println("Ruff! Ruff!");
} else {
System.out.println("Yip! Yip!");
}
}
} class GoodDogTestDrive {
public static void main(String[] args) {
GoodDog one = new GoodDog();
one.setSize(70);
GoodDog two = new GoodDog();
two.setSize(8);
System.out.println("Dog one : " + one.getSize());
System.out.println("Dog two : " + two.getSize());
one.bark();
two.bark();
}
}
class PoorDog {
private int size;
private String name; public int getSize() {
return size;
} public String getName() {
return name;
}
} class PoorDogTestDrive {
public static void main(String[] args) {
PoorDog one = new PoorDog();
System.out.println("Dog size is " + one.getSize());
System.out.println("Dog name is " + one.getName());
}
}
class Clock {
String time;
void setTime (String t) {
time = t;
} String getTime() {
return time;
}
} class ClockTestDrive {
public static void main(String[] args) {
Clock c = new Clock();
c.setTime("1245");
String tod = c.getTime();
System.out.println("time : " + tod);
}
}
class Puzzle4 {
public static void main(String[] args) {
Puzzle4b [] obs = new Puzzle4b[6];
int y = 1;
int x = 0;
int result = 0;
while (x < 6) {
obs[x] = new Puzzle4b();
obs[x].ivar = y;
y = y * 10;
x = x + 1;
}
x = 6;
while(x > 0) {
x = x - 1;
result = result + obs[x].doStuff(x);
}
System.out.println("result " + result);
}
} class Puzzle4b {
int ivar;
public int doStuff(int factor) {
if(ivar > 100) {
return ivar * factor;
} else {
return ivar * (5 - factor);
}
}
}

java第一章到第四章的更多相关文章

  1. “全栈2019”Java多线程第三十四章:超时自动唤醒被等待的线程

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  2. 《码出高效:Java开发手册》第四章学习记录,内容想当的多,前后花了几天的时间才整理好。

    <码出高效:Java开发手册>第四章学习记录,内容想当的多,前后花了几天的时间才整理好. https://naotu.baidu.com/file/e667435a4638cbaa15eb ...

  3. Kafka 权威指南阅读笔记(第三章,第四章)

    Kafka 第三章,第四章阅读笔记 Kafka 发送消息有三种方式:不关心结果的,同步方式,异步方式. Kafka 的异常主要有两类:一种是可重试异常,一种是无需重试异常. 生产者的配置: acks ...

  4. JAVA: httpclient 详细说明——第四章;

    httpclient 具体解释--第一章. httpclient 具体解释--第二章: httpclient 具体解释--第三章: httpclient 具体解释--第四章: httpclient 具 ...

  5. JavaScript DOM编程艺术-学习笔记(第三章、第四章)

    第三章: 1.js的对象分为三种:①用户自定义对象 ② 内建对象(js提供的对象) ③宿主对象(js寄宿的环境-浏览器,提供的对象) 2.文档是由节点组成的集合,即dom树,html元素是根元素,是唯 ...

  6. (第三章,第四章)http报文内的http信息,返回结果的http状态码

    第三章 http报文内的http信息 用于http协议交互的信息被称为http报文,包括请求报文和响应报文. 1.编码提升传输速率,在传输时编码能有效的处理大量的访问请求.但是编码的操作是计算机完成的 ...

  7. 算法导论 第三章 and 第四章

    第三章 渐进的基本O().... 常用函数 % 和  // 转换 斯特林近似公式 斐波那契数 第四章 分治策略:分解(递归)--解决(递归触底)--合并 求解递归式的3种方法: 1:代入法(替代法): ...

  8. java多线程编程核心技术——第四章总结

    第一节使用ReentrantLock类 1.1使用ReentrantLock实现同步:测试1 1.2使用ReentrantLock实现同步:测试2 1.3使用Condition实现等待/同步错误用法与 ...

  9. 《深入理解Java虚拟机》笔记--第四章、虚拟机性能监控与故障处理工具

    主要学习并记录在命令行中操作服务器时使用的六大命令工具,可视化工具JConsole和VisualVM在开发过程中熟悉. 一.jps:虚拟机进程状况工具(JVM Process Status Tool) ...

随机推荐

  1. ci 多个文件同时上传

    // 单个文件请手册,这里多个文件中,参数设置可参考手册 view 视图 <form...> <input type="file" name="user ...

  2. apache .htaccess 伪静态重定向,防盗链 限制下载...

    301全站跳转 RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.old\.net$ [NC]RewriteRule ^(.*)$ http://www.n ...

  3. php 验证码生成方法 及使用

    基本思路是: 在生成图片的页面中(as: yzm.php)1.设置生成的图片的宽度和高度:2.设置图片要写入的字符:3.截取显示在图片上的字符;4.开启session,把上面截取的字符存放在sessi ...

  4. python之PIL安装问题

    ··在windows安装模块 总是出现问题,今天安装PIL的 首先提示我的是pip命令出错,这应该是当你安装Python2.7的时候 并没有把pip模块添加进去 导致出现了这样的一个问题,为了省事,我 ...

  5. Ubuntu启动项设置——之update-rc.d 命令使用

    http://blog.csdn.net/typ2004/article/details/38712887 apache2.nginx.redis这些服务安装之后,会随开机启动,当这些服务并不需要时, ...

  6. C++ 11 笔记 (一) : lambda

    时至今日都是我咎由自取,错就是错,与任何人无关.掉进C++98的各种坑里无法自拔的抖M感,让我选择了华丽丽的无视C++11,导致今日面对开源的代码到各种看不懂的地步,一入C++深似海,我今天愿意承担一 ...

  7. 我终于忍不住喷一下某些书了,关于Java传引用的XX言论

    凡是说Java对象传的是引用,简直一派胡言,尤其误导我这种Java初学者,更严重的是以前用过C++的Java初学者. 我们都知道Java建立对象一般都是需要这样的格式: Object obj = ne ...

  8. Excel Skill (1) -- 判断时如何去掉框里的空格

    使用命令 TRIM 说明: Purpose. Remove extra spaces from text. Text with extra spaces removed. =TRIM (text) t ...

  9. Html DOM 常用属性和方法

    Node对象的节点类型***************************************************接口 nodeType常量 nodeType值 备注Element Node ...

  10. SAP修改前台屏幕字段文本

        首先,要找到需要修改文本所对应的数据元素: 其次,进入CMOD,点击菜单栏中“转到--文本增强--关键字--更改”,填入数据元素,进入下一屏幕.将显示的文本全部改为自己需要的文本,保存即可.