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. 【转】CHAR CHARACTER VARCHAR NCHAR NVARCHAR NVARCHAR2区别

    http://blog.csdn.net/lhl6688/article/details/44156823?ref=myread oracle提供了五种字符数据类型:char.nchar.varcha ...

  2. DIV+CSS 网页布局之:一列布局

    1.网页布局 布局(layout)即对事物的全面规划和安排,页面布局是对页面的文字.图像或表格进行格式化版式排列.网页布局对改善网站的外观非常重要,又称版式布局,大多数网站会把内容安排到多个列中,就像 ...

  3. input多选图片与显示

    input标签 在使用input选择文件时遇到了 在遍历input file.files 只显示最后一个,修改如下: CSS: <style type="text/css"& ...

  4. Boost1.62+win7+VC2015编译

    下载 通过boost官方网站, 或直接在source forge下载boost_1_62_0. 可选包 Zlib library, 环境变量: ZLIB_SOURCE bzip2, 环境变量: BZI ...

  5. c++11的for新用法 (重新练习一下for_each)

    看到手册的代码里面有个for的很奇怪的用法,用了一把    http://www.cplusplus.com/reference/unordered_set/unordered_set/insert/ ...

  6. uboot start.S分析

    一.概述   1.本文综述及特色  阅读uboot,start.S是第一个源程序文件,主要完成初始化看门狗.定时器.重定位(拷贝代码段到内存中).初始化堆栈.跳转到第二阶段等工作. 网上关于这些内容的 ...

  7. Java Fx-安装E(FX)CLIPSE IDE

    安装E(FX)CLIPSE IDE 本文主要介绍如何在Eclipse Mars 4.5.0版本上安装e(fx)clipse. 本文中的介绍和截图使用了纯净安装的为RCP和RAP开发者准备的Eclips ...

  8. phpwind9.0 顶部和底部版权信息永久性修改

    过了pw头部和底部版权修改方法,但是每次升级程序后版权又变成了默认的了,还得重新修改,其实有个方法可以永久性修改,底部和顶部随着主题走. pw9全局主题位于/themes/site/目录下,  前面文 ...

  9. 【技术贴】解决Mysql启动服务报错1067 进程意外终止

    无法启动MYSQL服务错误1067 进程意外终止. 我使用2013-10-25_appserv-win32-2.6.0.exe安装的MySql,结果服务起不来. 于是细心机智的我发现,在F:\stud ...

  10. Eclipse怎样导入github上的项目

    国外有些比较好的源代码网站,经常需要从这些网站上导入项目到eclipse中,我最近就发现github.com这个网站上有很多开源项目.这里就以从github网站上导入项目到eclipse中为例来详细的 ...