小编Dav*_*vid的帖子

撇号在java中意味着什么

在我正在学习的书中,我遇到了这个代码snippit:

while (i < len) { 
char c = s.charAt(i); 
if (c == ’(’) { 
count = count + 1; 
} else if (c == ’)’) { 
count = count - 1; 
} 
i = i + 1; 
} 
Run Code Online (Sandbox Code Playgroud)

撇号是什么意思(c == '(')?这里也没有语法错误?它看起来像(c == '(')需要另一个).

那怎么样else if (c == ’)’)

java

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

Java"XXX已在main中定义"错误

这是程序:(文件名是date.java)

class date {
    public static void main (String[] args) {
    int day, hour, minute;
    String firstline, half;

    firstline="the current imaginary time is:";
    day=24;
    hour=5;
    minute=36;

    String half;
    half="PM" ;


    System.out.println ("here is some program about the time kindof:");
    system.out.print (firstline) ;
    system.out.print (day) ;
    system.out.print (hour) ;
    system.out.print (":") ;
    system.out.print (minute) ;
    system.out.println (half) ;

    }
    }
Run Code Online (Sandbox Code Playgroud)

这是当我尝试在终端中编译它时会发生什么:

david-allenders-macbook-pro:~ davidallender$ javac date.java
date.java:11: half is already defined in main(java.lang.String[])
    String half;
               ^
date.java:15: package system does not exist …
Run Code Online (Sandbox Code Playgroud)

java compiler-errors

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

我如何导入AWT?

我正在教自己java和我正在寻找的书只是解释AWT.

这是我的源代码:

java.awt.*

class obj
{
    public static void main (String[]arg)
    {
        Point blank; 
        blank = new Point (3,4) ; 
        int x = blank.x ;
        System.out.prinln (x) ; 
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我在尝试编译时得到的错误:

obj.java:1: 'class' or 'interface' expected
java.awt.*
^
1 error
Run Code Online (Sandbox Code Playgroud)

我做错了什么?/这里出了什么问题?

java awt

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

类或接口预期错误(java)

当我尝试编译这个:

    public static int compareCardhl (Card c1, Card c2) 
}
if (c1.suit > c2.suit) return 1 ; 
if (c1.suit < c2.suit) return -1 ; 
if (c1.rank > c2.rank) return 1 ; 
if (c1.rank < c2.rank) return -1 ;  
return 0; 
}
Run Code Online (Sandbox Code Playgroud)

我得到了很多课堂或互动预期的错误.他们都指向了if's.我也在最后得到一个; expected错误Card c2).

这里出了什么问题?

java

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

如何在Befunge-93中编译程序?

如何在Befunge-93中保存和编译程序?保存文件需要什么文件扩展名(如fileName.what)?那怎么编译呢?

befunge

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

究竟是什么.jar文件,我怎么创建一个?

究竟是什么.jar文件,我怎么创建一个?

jar

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

为什么要跳过这些行?(Java)的

这是源代码的相关位:

class Dice 
{ 
    String name ; 
    int x ; 
    int[] sum ;  
Run Code Online (Sandbox Code Playgroud)

...

public Dice (String name) 
{ 
    this.name = name ; 
    this.x = 0 ; 
    this.sum = new int[7] ; 
}
Run Code Online (Sandbox Code Playgroud)

...

    public static void main (String[] arg) 
    {
        Dice a1 = new Dice ("a1") ; 
        printValues (a1) ; 
    }

    public static void printDice (Dice Dice) 
    { 
        System.out.println (Dice.name) ; 
        System.out.println ("value: "+Dice.x) ; 
        printValues (Dice) ; 
    } 

    public static void printValues (Dice Dice) 
    { 
        for (int i …
Run Code Online (Sandbox Code Playgroud)

java methods

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

这是否会导致堆栈溢出错误?

增加对象的实例变量是否会导致堆栈溢出错误?

例如:

此方法(java)将导致堆栈溢出错误:

class StackOverflow {
    public static void StackOverflow (int x) 
    {
        System.out.println (x) ; 
        StackOverflow(x+1) ; 
    } 

    public static void main (String[]arg) { StackOverflow (0) ; 
} 
Run Code Online (Sandbox Code Playgroud)

但这会是吗?:( .....是我为缩短代码而设置的差距.它足够长.)

import java.util.*;
class Dice 
{ 
    String name ; 
    int x ; 
    int[] sum ;  
Run Code Online (Sandbox Code Playgroud)

....

public Dice (String name) 
{ 
    this.name = name ; 
    this.x = 0 ; 
    this.sum = new int[7] ; 
}
Run Code Online (Sandbox Code Playgroud)

....

public static void main (String[] arg) 
{
    Dice a1 = new Dice ("a1") ; …
Run Code Online (Sandbox Code Playgroud)

java stack-overflow recursion

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

插入排序O(n ^ 2)的最坏情况是什么?

插入排序的最坏情况是什么O(n^2)

我觉得如果要排序的数组已经按相反的顺序排序,那么第一个元素将比较第二个1次,第三个是2次,依此类推,所以总时间应该等于SUM {i=1->i=(n-1)} [n]但不等于n^2(例如,如果n=4那么总和是1+2+3=6.

这个网站说它因为每次插入都需要O(n)和那些那些O(n ^ 2).但是为什么每次插入都需要O(n),第一次插入不需要n-1插入可以取O(n)但第二次插入也不需要等等.只有插入无穷大的插入才能插入O(n).(这是因为有无数个元素,带有insirtion = O(n),所以插入需要的oens

language-agnostic sorting

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

这个javascript/HTML出了什么问题

我想我只需要第二双眼睛.div的onclick事件似乎不起作用.有任何想法吗?

<!DOCTYPE html> 
<html> 
 <head>
 <meta charset="UTF-8">
 <title="My First Program"/>

 <script type="text/javascript">
      window.onload = function(){
           window.alert("If you see me then the page has loaded"); 
           click(); 
      }

      //we do programming here 
      /*because
        it is 
        fun*/
      window.alert("Helo World!"); 

      function click(){
           window.alert("CLICK!!!!");
      }


 </script>

 </head>
 <body>
      <div>This web page will run my first program</div>
      <!--this will be awesome-->
      <br>
      <br>
      <br>
      <div id="d1" onclick="click()">Click me</div>
 </body>
Run Code Online (Sandbox Code Playgroud)

另外,对于记录,这不是我的第一个程序.

javascript javascript-events

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