I want to compute the moment of inertia of a (2D) concave polygon. I found this on the internet. But I'm not very sure how to interpret the formula...
Formula http://img101.imageshack.us/img101/8141/92175941c14cadeeb956d8f.gif
1) Is this formula correct?
2) If so, is my convertion to C++ correct?
float sum (0);
for (int i = 0; i < N; i++) // N = number of vertices
{
int j = (i + 1) % N;
sum += (p[j].y - p[i].y) * (p[j].x + …Run Code Online (Sandbox Code Playgroud) 我有两个char,我想把它们"按"在一起.
例如:
char c1 = 11; // 0000 1011
char c2 = 5; // 0000 0101
short int si = stitch(c1, c2); // 0000 1011 0000 0101
Run Code Online (Sandbox Code Playgroud)
所以,我首先尝试的是按位运算符:
short int stitch(char c1, char c2)
{
return (c1 << 8) | c2;
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用:我得到了short等于c2...... (1)为什么?
(但:c1和c2是我真正的应用程序负数...也许这是问题的一部分?)
所以,我的第二个解决方案是使用union:
union stUnion
{
struct
{
char c1;
char c2;
}
short int si;
}
short int stitch(char c1, char c2)
{
stUnion …Run Code Online (Sandbox Code Playgroud) 我有这个字符串:
foo bar 567 baz
Run Code Online (Sandbox Code Playgroud)
现在我想在每个数字之前添加String num:.
所以结果必须是:
foo bar num:567 baz
Run Code Online (Sandbox Code Playgroud)
这也必须工作:
foo 73761 barbazboom!! 87
result:
foo num:73761 barbazboom!! num:87
Run Code Online (Sandbox Code Playgroud)
搜索数字的正则表达式是这样的:[0-9]+
但我想用num:+ [匹配子字符串] 替换匹配的子字符串
我现在用数字写了一个例子,但另一个例子可以是:在每个电子邮件地址之前添加 Email found:
我有这个代码:
InputStream is = socket.getInputStream();
int b;
while ((b = is.read()) != -1)
{
System.out.println(b);
}
Run Code Online (Sandbox Code Playgroud)
一个字节,其范围是-128直到+127.
但其中一个打印的字节是210.
这是将读取byte转换为int?的结果?
(因此,negatif byte成为一个positif int)
如果是这样,我可以OutputStream通过将inta 转换为a 来做同样的事情byte吗?
谢谢,
Martijn
如果我有a vector<string*> *vect或a map<pair<string*, int*>, string*> *map,
如何清理所有内容(包括vector/map包含的所有对象)?
(一切(矢量,地图,内容,字符串,整数)分配new)
这够了吗:
delete vect;
delete map;
Run Code Online (Sandbox Code Playgroud) 在普通的html中,当我想指出一个表行时,我只写:
<tr onmouseover="javaScript_(jQuery)_Code_To_Add_Pointed_Out_Class"
onmouseout="javaScript_(jQuery)_Code_To_Remove_Pointed_Out_Class">
...
</tr>
Run Code Online (Sandbox Code Playgroud)
有没有办法在<h:dataTable>for JSF中执行此操作?与Primefaces或其他什么?
我为数据库访问做了一个准备好的声明,虽然它很有用但我不确定是什么问题.
它应该做的是取一个整数和一个字符串并根据这个更新数据库.
这是代码.与DB本身的连接有效,我知道这可以执行"正常"语句.
public void updateShipment(int shipmentNumber, String currentLocation)
throws SQLException {
String sql = "UPDATE shipments SET current_node=? WHERE shipment_id=?";
con.setAutoCommit(false);
pre = con.prepareStatement(sql);
pre.setInt(1, shipmentNumber);
pre.setString(2, currentLocation);
pre.executeUpdate();
con.commit();
pre.close();
con.setAutoCommit(true);
}
Run Code Online (Sandbox Code Playgroud) 我有2个JPanels和1个JFrame,当我点击一个按钮时我正试图在面板之间切换..我不想使用CardLayout,因为我想要不同的面板和CardLayouts我只需要两个相同的按钮.我的代码是:
package javaapplication2;
import javax.swing.JPanel;
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
public NewJFrame() {
initComponents();
}
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(121, 183, 60));
setSize(200, 300);
setResizable(false);
/**panel1**/
jButton1 = new javax.swing.JButton();
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton1.setText("jButton1");
panel1.setBackground(new java.awt.Color(121, 183, 60));
panel1.setMaximumSize(new java.awt.Dimension(100, 200));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(panel1);
panel1.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(164, 164, 164) …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个简单的用户界面,要求用户输入双精度类型数字,如果他们的输入不是双精度类型,程序应继续打印提示,直到用户输入有效的双精度类型。我下面的代码还不能正常工作,因为当用户输入有效的双精度类型时,程序不会执行任何操作,除非用户输入另一个双精度类型数字。我猜想 while 循环中的条件 (sc.hasNextDouble()) 消耗了第一个有效输入。如何纠正这个问题?多谢
Scanner sc = new Scanner(System.in);
System.out.println("Type a double-type number:");
while (!sc.hasNextDouble())
{
System.out.println("Invalid input\n Type the double-type number:");
sc.next();
}
userInput = sc.nextDouble(); // need to check the data type?
Run Code Online (Sandbox Code Playgroud) 我有一个简单的项目,其中包含带分割器的fxml.
所以fxml是这样的:
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="accordionproject.FXMLDocumentController">
<children>
<SplitPane fx:id="splitPane" dividerPositions="0.29797979797979796" focusTraversable="true" layoutX="60.0" layoutY="14.0" prefHeight="200.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</items>
</SplitPane>
</children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)
我想要的是仅使用java代码在分割器的左锚定窗格中插入一个vbox.
可以这样做吗?
我是fxml的新手,所以任何帮助都会被贬低.
先感谢您.