小编Jes*_*ssy的帖子

将像素转换为cm

如果我使用此公式的像素距离:

sqrt((x1-x2).^2+.(y1-y2)^2))
Run Code Online (Sandbox Code Playgroud)

我怎样才能把它转换成CM?

matlab pixel

4
推荐指数
1
解决办法
1万
查看次数

如何从数组中生成随机数

如何从数组中生成随机数?而不是从一个范围.

int n [] = {1,7,3,5,8,10,33,12,18}
Run Code Online (Sandbox Code Playgroud)

java arrays random

3
推荐指数
1
解决办法
2万
查看次数

如何在单个数组中存储数组

如何将数组存储在单个数组中?例如,我有四个不同的数组,我想将它存储在单个数组中int storeAllArray [],当我调用例如storeAllArray [1]时,我会得到这个输出[11,65,4,3,2,9,7]而不是单个元素?

int array1 [] = {1,2,3,4,5,100,200,400}; 
int array2 [] = {2,6,5,7,2,5,10};
int array3 [] = {11,65,4,3,2,9,7};
int array4 [] = {111,33,22,55,77};
Run Code Online (Sandbox Code Playgroud)

int storeAllArray [] = {array1,array2,array3,array2} //我希望将所有数组存储在数组中

for (int i=0; i<storeAllArray; i++){
   System.out.println(storeAllArray.get[0]); // e.g. will produce --> 1,2,3,4,5,100,200,400 , how can I do this?
}
Run Code Online (Sandbox Code Playgroud)

编辑:我怎样才能获得这样的输出?

   System.out.println(storeAllArray [0])  --> [1,2,3,4,5,100,200,400]; 
    System.out.println(storeAllArray [1])  --> [2,6,5,7,2,5,10];
    System.out.println(storeAllArray [2])  --> [11,65,4,3,2,9,7];
    System.out.println(storeAllArray [2])  --> [111,33,22,55,77];
Run Code Online (Sandbox Code Playgroud)

java arrays

3
推荐指数
1
解决办法
3万
查看次数

如何更改数组元素的值

int A = 300;
int B = 400;
int C = 1000;
int D = 500;

int []abcd = {A,B,C,D};
Arrays.sort(abcd);   // the sequence of array elements will be {300, 400, 500,1000}
Run Code Online (Sandbox Code Playgroud)

我想根据它们在排序后在数组中的位置来改变变量A,B,C,D的值.

例如,变量A位于索引0处,因此A的值变为1而不是300,变量B位于索引1处,因此B的值变为2而不是400,变量D位于索引2处,因此D的值变为3而不是500,变量C位于索引3,因此C的值变为4而不是1000,

变量的最终值为:A = 1; B = 2; C = 4; D = 3;

java arrays

2
推荐指数
2
解决办法
8万
查看次数

如何更改计时器格式

我创建了计时器.如何将计时器格式更改为秒,以便它不会是长号?谢谢

private long startTime  = System.currentTimeMillis();
Timer timer  = new Timer(1000, this);
timer.start();

timer.stop();
long endTime    = System.currentTimeMillis();
long timeInMilliseconds = (endTime - startTime);
Run Code Online (Sandbox Code Playgroud)

java format timer

1
推荐指数
1
解决办法
391
查看次数

重置计时器

我试图在单击按钮后根据当前时间重置计时器,但是它不起作用。救命 :-(

private long startTime  = System.currentTimeMillis();
Timer timer  = new Timer(1000, this);
timer.start();

timer.stop();
long endTime    = System.currentTimeMillis();
long timeInMilliseconds = (endTime - startTime);

timer.reset();
Run Code Online (Sandbox Code Playgroud)

java timer reset

1
推荐指数
1
解决办法
8587
查看次数

ActionListener问题

我的actionListener有问题.在我点击按钮之前,似乎actionListener会自动运行?在单击按钮之前,控制台中出现"这不应出现在控制台中的控制台之前"....这很奇怪.

.... 
button1.addActionListener(this); 
button2.addActionListener(this);
....
public void actionPerformed(ActionEvent e) {

   System.out.println("This should not appear in the console before button click");

   if (e.getSource()==button1)
      System.out.println ("answer1");

   else if (e.getSource()==button2)
      System.out.println ("answer2");
   .....
}
Run Code Online (Sandbox Code Playgroud)

java swing

1
推荐指数
1
解决办法
564
查看次数

循环MATLAB的问题

no  time  scores
1    10    123
2    11    22
3    12    22
4    50    55
5    60    22
6    70    66
.    .     .
.    .     .
n    n     n 
Run Code Online (Sandbox Code Playgroud)

在我的txt文件的内容之上(数千行).

1st column - number of samples
2nd column - time (from beginning to end ->accumulated)
3rd column - scores
Run Code Online (Sandbox Code Playgroud)

我想创建一个新文件,该文件将是每三个分数样本的总和除以同一样本的时差.

e.g. (123+22+22)/ (12-10) = 167/2 = 83.5
     (55+22+66)/(70-50) = 143/20 = 7.15
Run Code Online (Sandbox Code Playgroud)

新的txt文件

83.5
7.15
.
.
.
n
Run Code Online (Sandbox Code Playgroud)

到目前为止我有这个代码:

fid=fopen('data.txt')
data = textscan(fid,'%*d %d %d')
time = (data{1}) …
Run Code Online (Sandbox Code Playgroud)

matlab loops

1
推荐指数
1
解决办法
697
查看次数

如何比较数组中的值?

如何比较数组中的值?

我有数组命名列表,其中包含12个元素.我看到索引0中的值是否等于索引2中的值.

我试过这个代码,但似乎没有用.

if ((list.get(0)==list.get(2) && list.get(1)==list.get(3)) 
{
   System.out.println("equal")
}
Run Code Online (Sandbox Code Playgroud)

java arrays

0
推荐指数
1
解决办法
2万
查看次数

列出链接列表参考

如何在链接列表中获取数据引用/索引?

例如,如果我有这个链表

java.util.List<Polygon> triangles = new LinkedList<Polygon>();

polygon triangle, selectedTriangle;
Point startDrag,endDrag,midPoint;
....

triangles.add( new Polygon(xs, ys,3));    
Run Code Online (Sandbox Code Playgroud)

例如,如何将Polygon selectedTriangle设置为与链接数组列表中现有三角形之一相同?

编辑:

java.util.List<Polygon> triangles = new LinkedList<Polygon>();
polygon triangle, selectedtriangle;
....

triangles.add( new Polygon(xs, ys,3)); 
.....

public void mousePressed(MouseEvent e) {
....
  startDrag = new Point(e.getX(), e.getY());  
  endDrag   = startDrag;

  for (Polygon p : triangles) { 
    if (p.contains(startDrag)) {//inside triangle 

       //I dont know how to set the selectedTriangle as the same with existing triangle
       selectedTriangle = triangles.indexOf(p.contains(startDrag)); 
       break; //
    }
  }
..... …
Run Code Online (Sandbox Code Playgroud)

java linked-list list

0
推荐指数
1
解决办法
1325
查看次数

以随机顺序显示对

我如何随机化对的顺序?例如,我有3个元素存储在列表中,例如A,B,C - >,它们产生AB,AC,BC对.

如何以随机顺序显示对?例如AB,AC,BC BC,AB,AC AC,AB,BC

ArrayList<String> s = new ArrayList<String>();
  s.add("A");
  s.add("B");
  s.add("C");

ListGenerator lg = new ListGenerator(s);
Run Code Online (Sandbox Code Playgroud)

其他类

public class ListGenerator {

  private ArrayList<String> pairsX= new ArrayList<String>();

  public ListGenerator(ArrayList<String> list) {
    int size = list.size();
    int count_pairs = 0;

    // create a list of all possible combinations
    for(int i = 0 ; i < size ; i++)
    {
       String s1 = ""+i;
       for(int j = (i+1) ; j < size ; j++)
       {
          count_pairs++;
          String s2 …
Run Code Online (Sandbox Code Playgroud)

java arraylist

0
推荐指数
1
解决办法
303
查看次数

如何避免空指针错误

我试图找出2个arrayLists的元素是否匹配.但是这段代码给了我错误,Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException因为有些元素是null.

我怎样才能解决这个问题?

String level []={"High","High","High","High","High","High"};
ArrayList<Object> n = new ArrayList<Object>(Arrays.asList(level));

String choice []={null,"High","Low","High",null,"Medium"}; 
ArrayList<Object> m = new ArrayList<Object>(Arrays.asList(choice));

//Check if the two arrayList are identical
for(int i=0; i<m.size(); i++){
   if(!(m.get(i).equals(n.get(i)))){   
 result= true;
 break;
   } 
} 
    return  result;
}
Run Code Online (Sandbox Code Playgroud)

java null pointers arraylist

0
推荐指数
2
解决办法
1749
查看次数

标签 统计

java ×10

arrays ×4

arraylist ×2

matlab ×2

timer ×2

format ×1

linked-list ×1

list ×1

loops ×1

null ×1

pixel ×1

pointers ×1

random ×1

reset ×1

swing ×1