java代码--------编写0懂啊PI之间求随机数的方法
摘要:总结:其实每次运行,显示出来的结果个数是随机的。package com.mmm;//编写0到PI之间求随机数的方法public class MEm { public static void main(String[] args) { double ra = 0.0; while (true) { if ((ra = Math.random() * 10) < Math.PI) { break;// 输出的数是小于圆周率的数 } System.out.println(ra); } }}//8.6286213551390875.2886580632992426.936161...
阅读全文
posted @
2013-12-30 07:09
juewang
阅读(238)
推荐(0)
java代码------charAt()的用法
摘要:总结:你看这个方法的用处真的蛮多比如这个计算器小项目,用这个charAt()方法来装运算符package com.mmm;import java.util.Scanner;public class Bing { public static void main(String[] args) { String str = "eeesafsa"; int count = 0; // if(){} // int count=0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'e')
阅读全文
posted @
2013-12-29 22:45
juewang
阅读(1748)
推荐(0)
java代码--------构造方法的调用
摘要:总结:package com.sads;//构造方法何时被调用,//构造方法里的内容先执行public class Sdw { static { System.out.println("呦呦呦"); } Sdw(int a) { System.out.println("这是执行有参构造方法的代码"); } Sdw() { System.out.println("这是执行无参构造方法代码"); }// 构造方法总 是先执行无参数的构造方法,再执行有参数的构造方法 public static void main(String[] args
阅读全文
posted @
2013-12-29 08:40
juewang
阅读(347)
推荐(0)
java代码--------随机输出100个随机数,要求每行10个数
摘要:总结:不敢爱你么开口package com.sads;///实现随机输出100个数字,数字是0到9之间,每行输出10个public class Wss { public static void main(String[] args) { int a[] = new int[100]; for (int i = 0; i < 100; i++) { a[i] = (int) (Math.random() * 10); } for (int i = 0; i < 100; i++) { if (i % 5 == 0) {// 代码是把100个数分成每行10个数,5个数,排列 ...
阅读全文
posted @
2013-12-29 07:52
juewang
阅读(1735)
推荐(0)
java代码-----------继承练习
摘要:总结:父类和子类拥有相同的方法时,父类的方法被覆盖,子类package com.sads;class fong { void pprint() { this.print(); this.printl(323); } void print() { System.out.println("父类:同类型、同名、同参数成员方法"); } private void printl(int i) { // TODO Auto-generated method stub System.out.println("父类:同类型,同名,但参数不同的成员方法"); }}clas
阅读全文
posted @
2013-12-29 07:39
juewang
阅读(316)
推荐(0)
java代码---------实现布尔型的功能,是否执行下一步的关键
摘要:总结:灵活package com.sads;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;//我记得,final。finally//前者放在类前面是类不能被继承,放在方法前面是方法不能被改变,放在变量前面是常量不改变//而后者是异常里的清除释放资源的操作,与final是没有任何关系public class sdf { public static void main(String[] args) throws IOException { InputStreamR.
阅读全文
posted @
2013-12-29 00:55
juewang
阅读(455)
推荐(0)
java代码--------实现随机输出100个随机数,10行,0--到9的数字
摘要:总结:妹纸不是那么会表述,如有不妥之处,请提出来package com.sads;//杰伦的世界//实现在0-100个数中,随机输出数每行10个数,也就是10行10列,这些数在0---到9之间public class Dds { public static void main(String[] args) { int a[] = new int[100]; for (int i = 0; i int是大范围转换为小范围,要强制转换 // 这里从100个随机数里,存着任意10个随机数。 } for (int i = 0; i < 100; i++) { if (i % 10 ==...
阅读全文
posted @
2013-12-29 00:07
juewang
阅读(2085)
推荐(0)
java代码--------打印三角形
摘要:总结:这里主要是for循环里的j<=i而不死j<=i-1;.还有先打印“*”再打印空格。换行。理解。请用脑子啊package com.sads;public class Dds { public static void main(String[] args) { for(int i=0;i<=5;i++){ for(int j=1;j<=i;j++){ System.out.print("* "); } System.out.println(""); } }}//* * * * * * * * * * * * * * *
阅读全文
posted @
2013-12-28 23:47
juewang
阅读(375)
推荐(0)
java代码------------条件运算符 ?:
摘要:总结:package com.sads;//?://这个运算符是条件运算符//条件式?值:值public class Sd { public static void main(String[] args) { int x=10; int y=20; int max=x>y?x:y; System.out.println(max);//-----20 int a=-10; int abs=a>0?a:-a; System.out.println(abs);//=-==10 }}2010
阅读全文
posted @
2013-12-28 08:06
juewang
阅读(279)
推荐(0)
java代码-----------逻辑运算符、 &&逻辑与 ||或
摘要:总结:&& :两者均满足。是true||: 两者中有一个满足就为true,不然就是falsepackage com.sads;public class shou { public static void main(String[] args) { int n=2; // boolean b=!(n>=0)&&(n=10);//这里有两种方式 0-----||这是逻辑或//当条件中有一个满足时,就为ture,不然就是false System.out.println(b2);//是false }}
阅读全文
posted @
2013-12-28 07:49
juewang
阅读(423)
推荐(0)
java代码------计算器
摘要:总结:我用if()语句写计算功能的代码时,实现不了,与switch_-catch语句不一样。不知到怎么实现package com.p;import javax.swing.*;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;//这是一个计算器//用的是网格布局管理器,不是纯按钮组合,发现class calc extends JFrame implements ActionListener {
阅读全文
posted @
2013-12-27 23:23
juewang
阅读(377)
推荐(0)
java代码---charAt()和toCharry()的用法
摘要:总结:charAt()是返回字符型,把字符串拆分成某个字符,返回指定位置的字符。可以把字符串看成char型数组package com.sads;///输出一个大写英文字母的public class XIE { public static void main(String[] args) { String s="hello world i lkie fjds"; char c=s.charAt(6); System.out.println(c);// 该字符串返回第几个索引的字符 char[] x=s.toCharArray();//你妹自动纠错,是数组,不是char类型 S
阅读全文
posted @
2013-12-27 07:32
juewang
阅读(773)
推荐(0)
java代码-----计算器,界面+功能+boolean
摘要:总结:还是那个不懂代码放在哪里好?不知道怎么定义一些关键性变量。比如boolean 型的。package com.sads;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class Test { public static void main(Str
阅读全文
posted @
2013-12-27 01:04
juewang
阅读(521)
推荐(0)
java代码-----运用endWith()和start()方法
摘要:总结:package com.a.b;//startWith().和endWith()是检查一个字符串是否以一个特定的字符序列开始或结束public class Sdfs { public static void main(String[] args) { String t1 = "I like java"; String startStr = "I"; String endStr = "java";// 这里java是区分大小写的。所以字母全部一模一样 if (t1.startsWith(startStr)) System.out.
阅读全文
posted @
2013-12-24 22:22
juewang
阅读(957)
推荐(0)
java代码---indexOf()方法
摘要:总结:indexOf(String str,int index)方法.从参数指定位置开始,如果index值超过了字符串长度,则返回-1package com.a.b;import java.io.*;public class Chen { public static void main(String[] args) throws IOException { //线程。继承。抽象 String test="After learning the material"; String theStr="arn"; int index=0,theCount=0; i
阅读全文
posted @
2013-12-24 22:00
juewang
阅读(552)
推荐(0)
java代码----------实现创建DataInputStream和DataOutputStream进行读写
摘要:总结: 主要是 捕获异常package com.a.b;import java.io.*;public class testData { public static void main(String[] args) throws IOException { File newDir = new File("c:\\javas"); if (!newDir.exists()) { newDir.mkdir();// 如果目录不存在,就创建目录 File newFile = new File(newDir, "test.txt"); try { newFile
阅读全文
posted @
2013-12-24 07:45
juewang
阅读(300)
推荐(0)
java代码-----实现有键盘获得的字符串存储在文件中,并从文件中读取后显示在屏幕上
摘要:总结:没体会到package com.a.b;import java.io.*;public class tsetOut { public static void main(String[] args) throws IOException { char ch; int i; File newDir=new File("C:\\JavaTest2"); if(!newDir.exists()){ newDir.mkdir(); File newFile=new File(newDir,"newTest.txt"); FileOutputStream ou
阅读全文
posted @
2013-12-24 00:04
juewang
阅读(479)
推荐(0)
java代码---------实现File的目录下创建文本文档
摘要:总结:虽然他没教给我们很多,但是他已经很棒了package com.a.b;import java.io.*;public class dd { public static void main(String[] args) throws IOException { File f = new File("C:\\ttee"); if (!f.exists()) { f.mkdir(); } File f2 = new File(f, "yue.txt"); f2.createNewFile();// 这里因为有f1传了个参数,所以在目录下创建了一个文本文档
阅读全文
posted @
2013-12-23 23:47
juewang
阅读(279)
推荐(0)
java代码-----实现4个人打牌游戏的相关代码。线程
摘要:总结:发送线程Sender().和接收线程Receiver()虽然,这里的Sender()发送线程和Receiver()都有相同的睡眠时间,但是由于线程调度的不确定性,是的发送线程Sender每次发送的数据和接收线程Receiver每次接收的数据不一样。而我们希望的是发送线程每次发送的数据都能够让接收线程Receiver正确的接收 到,这就必须增加方法的锁定机制。package com.a.b;//package com.a.b;class Buffer2 {// 这里注意java源文件不是Buffer.java(文件名)否则运行出错。根本无法显示 private int value; //
阅读全文
posted @
2013-12-23 23:01
juewang
阅读(1034)
推荐(0)
java代码-------Runnable的用法
摘要:总结:主要是实现Runnable接口就必须重写run()方法,然后需要创建Thread类的对象,再调用start()方法package com.s.x;public class testRunnable implements Runnable { int k = 0; public testRunnable(int k) { this.k = k; } public void run() { int i = k; System.out.println(); while (i < 30) { System.out.print(i + "");// 这里应该输出的是,0,
阅读全文
posted @
2013-12-23 22:24
juewang
阅读(8193)
推荐(0)