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. NetSerialComm的基本使用方法

    近期搞一个com口传输的小项目,原来认为是一个挺简单的一个小功能,结果生产商发来com以后直接傻眼了,还要对相关的硬件流进行处理 如下 // 硬件流控制设置 dcb.fOutxCtsFlow = FA ...

  2. DOM Ready 详解

    DOM Ready 概述 熟悉jQuery的人, 都知道DomReady事件. window.onload事件是在页面所有的资源都加载完毕后触发的. 如果页面上有大图片等资源响应缓慢, 会导致wind ...

  3. php图片上传代码

    使用copy函数 if (!empty($_FILES)) { //图片 if(isset($_FILES['image'])) { $img_data = $_FILES['image']['tmp ...

  4. skip index scan

    官网对skip index scan的解释: Index skip scans improve index scans by nonprefix columns since it is often f ...

  5. SpringMVC Maven创建项目

    一.配置Maven环境: 1.去官网下载好Maven,并解压: 2.添加环境变量: ①添加环境变量,如下: ②把maven的bin目录添加到环境变量path下面,如下(我系统是win10,win7编辑 ...

  6. ubuntu16.04添加开机启动任务

    比如要把run-nexus.sh这个脚本制作成开机启动项. 系统工具->首选项->启动应用程序.添加该文件,即可.

  7. ios解决输入框弹出后position:fixed失效问题

    最近在使用AmazeUI进行仿App Mobile Web开发时遇到了讨论众多的position:fixed问题.position:fixed在安卓2.2以上已经实现,但是在ios8以下系统当小键盘激 ...

  8. Android用户界面 UI组件--TextView及其子类(三) EditView以及各种Span文字样式讲解

    EditView和TextView的用法差不多,只是文字可编辑 小技巧: 设置EditText隐藏键盘  setInputType(0); 设置EditText不被输入法遮盖  getWindow() ...

  9. CodePen避免自动刷新导致的JS卡死

    经常需要做一些前端代码的实验, 这时候我往往会用JSFiddle或CodePen. 最近用CodePen更多一些, 里面提供的选项更加丰富, 提供了各种各样的HTML/Javascript/CSS P ...

  10. AS 学习笔记 for in 和 for each in

    for in 的速度比 for each  in 慢很多倍 ~~ var myArray:Array = new Array(); myArray["a"] = "zer ...