包含javasphere的词条
今天给各位分享javasphere的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
Java 类Sphere求 3D球体积,用Testpheres测试?
public class TestSphere {
public static void main(String[] args) {
//0
System.out.println("count="+Sphere.getCount());
//1
Sphere s1=new Sphere(0,5,6,7);
System.out.println("count="+Sphere.getCount());
//2
Sphere s2=new Sphere(10,3,7,5);
System.out.println("count="+Sphere.getCount());
//volume
System.out.println("volume="+s1.volume());
System.out.println("volume="+s2.volume());
}
}
class Sphere{
static final double PI=3.14;
static int count;
private double xCenter,yCenter,zCenter,radius;
Sphere(double theRadius,double x,double y,double z){
this.xCenter=x;
this.yCenter=y;
this.zCenter=z;
if(theRadius=0) {
this.radius=getRadius();
}else {
this.radius=theRadius;
}
count++;
}
public static int getCount() {
return count;
}
public double volume() {
return getNum((4.0/3.0)*(Math.pow(radius, 3))*PI);
}
private double getRadius() {
this.radius=getNum(Math.sqrt(getDou(xCenter)+getDou(yCenter)+getDou(zCenter)));
return this.radius;
}
private double getDou(double num) {
return Math.pow(num, 2);
}
private double getNum(double num) {
return new java.math.BigDecimal(num).setScale(3, 4).doubleValue();
}
}
Java 圆类
public class Sphere{
private int xpos,ypos,zpos,radius;
public Sphere(){
xpos=0;
ypos=0;
zpos=0;
radius=1;
}
public Sphere(int x, int y, int z, int r){
xpos=x;
ypos=y;
zpos=z;
radius=r;
}
public String toString(){
String s="";
s="x-coordinate: "+xpos+",y-coordinate: "+ypos+",z-coordinate: "+zpos+",radius: "+radius;
return s;
}
public boolean equals(Object obj){
Sphere s=(Sphere)obj;
if(this.xpos==s.xposthis.ypos==s.yposthis.zpos==s.zposthis.radius==s.radius) return true;
else return false;
}
public double surface(){
return Math.PI*4*radius*radius;
}
public double volume(){
return Math.PI*4/3*radius*radius*radius;
}
public int relativeLocation(Sphere s){
int distanceSquare=(this.xpos-s.xpos)*(this.xpos-s.xpos)+(this.ypos-s.ypos)*(this.ypos-s.ypos)+(this.zpos-s.zpos)*(this.zpos-s.zpos);
double distance=Math.sqrt(distanceSquare);
if(distancethis.radius+s.radius) return -1;
else if(distance==this.radius+s.radius) return 0;
else return 1;
}
public static void main(String[] args){
Sphere s1=new Sphere(0,0,0,1);
Sphere s2=new Sphere(10,10,10,10);
System.out.println(s1);
System.out.println("The surface area of s1 is "+s1.surface()+" and the volume is "+s1.volume());
System.out.println(s2);
System.out.println("The surface area of s1 is "+s2.surface()+" and the volume is "+s2.volume());
int i=s1.relativeLocation(s2);
switch(i){
case 1: System.out.println("The two balls intersect each.");break;
case 0: System.out.println("The two balls are tangent to each.");break;
case -1: System.out.println("The two balls are away from each.");break;
}
}
}
如何用java 监控websphere是否正常运行
告诉你一个简单的办法,你先看看你websphere的端口是多少,然后写几行代码,也去偿试监听这个端口,因为这个端口已经被占用了,会报异常,这时候说明websphere是正常的,只要你的这个小程序端口监听成功了,你就可以理解为websphere挂了
如何在java中使用WebSphere MQ
websphere mq : 用于传输信息 具有跨平台的功能。
1 安装websphere mq 并启动
2 websphere mq 建立 queue Manager (如:MQSI_SAMPLE_QM)
3 建立queue 类型选择 Local类型 的 (如lq )
3 建立channels 类型选择Server Connection (如BridgeChannel)
java 代码如下:
package test.mq;
import com.ibm.mq.*;
/*
* 成功的访问mq 的java 类
*/
public class FirstMqTest {
// public static void main(String[] args[]){
// FirstMqTest first = new FirstMqTest();
// first.test();
// }
public static void main(String args[]){
FirstMqTest first = new FirstMqTest();
first.test();
}
public void test(){
String qManager = "MQSI_SAMPLE_QM"; //QueueManager name
String qName = "lq";//Queue Name
try {
//configure connection parameters
MQEnvironment.hostname="172.16.17.123";//MQ Server name or IP
//MQEnvironment.port=1414;//listenr port
MQEnvironment.channel="BridgeChannel";//Server-Connection Channel
MQEnvironment.CCSID =1381;
// Create a connection to the QueueManager
System.out.println("Connecting to queue manager: "+qManager);
MQQueueManager qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we wish to open and the open options
System.out.println("Accessing queue: "+qName);
MQQueue queue = qMgr.accessQueue(qName, openOptions);
// Define a simple WebSphere MQ Message ...
MQMessage msg = new MQMessage();
// ... and write some text in UTF8 format
msg.writeUTF("Hello, World!");
// Specify the default put message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
// Put the message to the queue
System.out.println("Sending a message...");
/*
* 在此测试一下 mq 的传输次列
*
*/
for(int j=0;j 5;j++){
String str ="test11111111111";
str = str+j;
msg.writeUTF(str);
queue.put(msg, pmo);
}
queue.put(msg, pmo);
// Now get the message back again. First define a WebSphere MQ message
// to receive the data
MQMessage rcvMessage = new MQMessage();
// Specify default get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();
// Get the message off the queue.
System.out.println("...and getting the message back again");
queue.get(rcvMessage, gmo);
// And display the message text...
String msgText = rcvMessage.readUTF();
System.out.println("The message is: " + msgText);
// Close the queue
System.out.println("Closing the queue");
queue.close();
// Disconnect from the QueueManager
System.out.println("Disconnecting from the Queue Manager");
qMgr.disconnect();
System.out.println("Done!");
}
catch (MQException ex) {
System.out.println("A WebSphere MQ Error occured : Completion Code "
+ ex.completionCode + " Reason Code " + ex.reasonCode);
}
catch (java.io.IOException ex) {
System.out.println("An IOException occured whilst writing to the message buffer: "
+ ex);
}
}
}
javasphere的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javasphere的信息别忘了在本站进行查找喔。
发布于:2022-11-26,除非注明,否则均为
原创文章,转载请注明出处。