Ⅰ java,已知兩點坐標,設任意頂點,求弧線. 求公式及Java代碼演示.
改變弧頂也是改變;圓的半徑,
java的畫圖方法,是你輸入的點畫做矩形畫圖,圓也是一樣,
X,Y並不回是圓心,算一下偏答移量,做一個X,Y是圓心的方法,
然後是根據兩點及弧高算半徑,(這是數學問題了)
知道了上面的內容就可以畫你想要的弧了,
以上是思路,好長時間不畫圖了,有些手生,如果你不著急,周末給你貼出代碼
Ⅱ 用Java實現棵普通的叉樹,給定 叉樹的兩個節點 nodeA、nodeB,找到nodeA和nodeB的最短路徑,並輸出。
publicclassPath{
publicstaticList<Node>minPath(Noderoot,Nodea,Nodeb){
List<Node>result=newArrayList<Node>();
if(root==null||a==null||b==null){
returnresult;
}
List<Node>aPath=path(root,a);
List<Node>bPath=path(root,b);
intlastSameNodeIndex=getLastSameNodeIndex(aPath,bPath);
if(lastSameNodeIndex==-1){
returnresult;
}
for(inti=aPath.size()-1;i>=lastSameNodeIndex;i--){
result.add(aPath.get(i));
}
for(inti=lastSameNodeIndex+1;i<bPath.size();i++){
result.add(bPath.get(i));
}
returnresult;
}
(List<Node>aPath,List<Node>bPath){
inti=-1;
while(i+1<aPath.size()&&i+1<bPath.size()
&&aPath.get(i+1)==bPath.get(i+1)){
i++;
}
returni;
}
privatestaticList<Node>path(Noderoot,Noden){
List<Node>result=newArrayList<Node>();
result.add(root);
if(root==n){
returnresult;
}
if(root.left!=null){
List<Node>left=path(root.left,n);
if(left.size()>0){
result.addAll(left);
returnresult;
}
}
if(root.right!=null){
List<Node>right=path(root.right,n);
if(right.size()>0){
result.addAll(right);
returnresult;
}
}
result.clear();
returnresult;
}
}
publicclassNode{
publiccharvalue;
publicNodeleft;
publicNoderight;
publicNode(charvalue){
this.value=value;
}
}
Ⅲ 請問你提的這個問題解決么「java 如何比較兩個xml的某一節點完全相同」
先用工具解析xml,比如dom4j什麼的,然後分別獲取你想要比較的節點,然後比較節點內容。
Ⅳ java可以判斷倆個鏈表的公共子節點嗎如果可以,請舉例
Collections類的disjoint()方法可以判斷給定的2個集合中是否包含相同元素
disjoint
public static boolean disjoint(Collection<?> c1,
Collection<?> c2)
如果兩個指定 collection 中沒有相同的元素,則返回 true。
如果將此方法用在不符合 Collection 常規協定的 collection 上,則必須小心。實現可以在任一 collection
上進行迭代,測試元素是否包含在另一個 collection 中(或執行任何等效的計算)。如果任一 collection
使用了一個非標準的相等性測試(比如順序不是與 equals 一致的 SortedSet,或者 IdentityHashMap
的鍵集),則兩個 collection 都必須使用相同的非標准相等性測試,否則此方法的結果是不確定的。
注意,允許在兩個參數中傳遞相同的 collection,在這種情況下,當且僅當 collection 為空時此方法返回 true。
參數:
c1 - 一個 collection
c2 - 一個 collection
拋出:
NullPointerException
- 如果任一 collection 為 null
從以下版本開始:
1.5
Ⅳ 已知兩個坐標軸上的數值點怎麼用java做一個折線圖
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class t3 extends JFrame {
t3()
{
.setSize(200, 200);
this.setDefaultCloseOperation(3);
this.setVisible(true);
}
public static void main(String[] args)throws Exception{
new t3();
}
Point[] p = new Point[]{new Point(1,1),new Point(11,31),new Point(31,21),new Point(99,100)};
public void paint(Graphics g)
{
Image img = (Image)new BufferedImage(200,200,BufferedImage.SCALE_DEFAULT);
Graphics gg = img.getGraphics();
for(int i=0;i<p.length-1;i++)
{
gg.drawLine(p[i].x, 200-p[i].y,p[i+1].x, 200-p[i+1].y);
}
g.drawImage(img, 0, 0, null);
}
}