public class PointTest {
public static void main(String[] args) {
Point p1 = new Point(1,2);
Point p2 = new Point(1,20);
java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
double d = p2.distance(p1);
System.out.println(df.format(d));
}
}
......
Java代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://xiaoxinshome.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" quality="high" flashvars="clipboard=%20%20%20%20%20java.util.Properties%20pp%20%3D%20System.getProperties()%3B%0A%20%20%20%20%20%20%20%20java.util.Enumeration%20en%20%3D%20pp.propertyNames()%3B%0A%20%20%20%20%20%20%20%20while%20(en.hasMoreElements())%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20String%20elm%20%3D%20(String)%20en.nextElement()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.print(elm%20%2B%20%22%20----%3E%22%20%2B%20pp.getProperty(elm))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20System.out.println()%3B%0A%20%20%20%20%20%20%20%20%7D">
java.util.Properties pp = System.getProperties();
java.util.Enumeration en = pp.propertyNames();
whil ......
//从数组a中删除数组b中存在的元素
String stra[] = {"g","b","c","h","k"};//原始数组
String strb[] = {"g","k"}; //移除的元素
ArrayList list = new ArrayList();
//方法一
for(int i=0;i<stra.length;i++){
int n=0;
for(int j=0;j<strb.length;j++){
if(stra[i].equals(strb[j])){
n++;
}
}
if(n==0){
list.add(stra[i]);
}
}
// //方法二
// for(int j=0;j<stra.length;j++){
// if(java.util.Arrays.binarySearch(strb, stra[j])<0){
// list.add(stra[j]);
// }
// }
//得到新的数组c
Object[] strc = (Object[])list.toArray(); ......
public static void CentreWnd(Shell shell){
int width = shell.getMonitor().getClientArea().width;
int height = shell.getMonitor().getClientArea().height;
int x = shell.getSize().x;
int y = shell.getSize().y;
if (x > width) {
shell.getSize().x = width;
}
if (y > height) {
shell.getSize().y = height;
}
shell.setLocation((width - x) / 2, (height - y) / 2);
} ......
同样的程序,在别人的电脑上都可以用,在我的电脑上却无论如何都通不过,郁闷啊。
昨天遇到一个问题搞了一天都没有解决,
这个程序在别人的电脑上用都可以通过,只有在我的电脑上无法通过
,我一开始装的是JDK6.0,后来卸载了装成了JDK5.0(为了和所学教程保持一致,
以及我宿舍通过测试的机器也是装的JDK5.0),
但是依然通不过,郁闷中,希望各位高手帮忙解决。
程序代码如下:
----服务器端
import java.io.IOException;
import java.net.*;
public class TCPServer {
public static void main(String[] args) throws Exception{
ServerSocket server = new ServerSocket(97); //binding listening
Socket s = server.accept(); //blocking
System.out.println("a client connect!");
}
}
----客户端
import java.net.*;
public class TCPClient {
public static void main (String args[]) throws Exception {
Socket s = new Socket("127.0.0.1",97);
}
}
---结果:
D:\java\ten>java TCPserver
Exception in thread "main" java.net.BindException:Cannot assign reguested address:JVM_Bind
at ......
URI 是资源标识符。就是相当于一个人的家庭住址。
URL和URI类似。是资源定位的。 和URI不同的就是URL提供了获取东西的方法。
java.io.InputStream l_urlStream;
// 也可以换成uri,然后调用uri.toURL
java.net.URL l_url = new java.net.URL(
"http://www.google.cn");
java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url
.openConnection();
System.out.println(l_connection.getContentType());
l_connection.connect();
l_urlStream = l_connection.getInputStream(); ......