小编Ant*_*ney的帖子

一个javascript摇滚,纸,剪刀游戏!

嘿伙计们,我正在制作一个javascript摇滚,纸张,剪刀游戏!所以代码在下面,它不起作用警报没有显示,我真的不知道我搞砸了.

function randomNumber(x,y){                 //returns a random number from an interval given
    var z;
    if (x>y) {z=x; x=y; y=z;}               // turns the interval upside down if the numbers of the interval are entered in unconsecutive order
    else if(x==y) {return x; break;}        //if there's no interval but two same digits return the number entered
    var randomNo = (y-x)*Math.random() + x; // the random value itself in float type
    Math.round(randomNo);                   // round it to integer
}

function outcomeType(value){                    //gives the type of hand-symbol …
Run Code Online (Sandbox Code Playgroud)

javascript

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

Android RadioButton返回一个常量?

我正在尝试执行评级系统,其中选择的选项返回一个常数,以便我可以将值插入数据库.我的意图是有三个选择,'伟大','平庸'和'坏'.我希望Great为'3'的常数,Mediocre为常数'2'而Bad为常数为'1'.如果可能,我想只插入数值,任何简单的方法吗?

安东尼

database android constants radio-button

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

我在主线程中得到异常......即使我处理异常

public KalaGame(KeyBoardPlayer player1,KeyBoardPlayer player2)
 {   //super(0);
 int key=0;
 try
 {

     do{
     System.out.println("Enter the number of stones to play with: ");

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
        key = Integer.parseInt(br.readLine());  


    if(key<0 || key>10)
  throw new InvalidStartingStonesException(key);
  }
 while(key<0 || key>10);
    player1=new KeyBoardPlayer();
   player2 = new KeyBoardPlayer(); 
   this.player1=player1;
   this.player2=player2;
   state=new KalaGameState(key);



 }


    catch(IOException  e)
    {
       System.out.println(e);
      }
     } 
Run Code Online (Sandbox Code Playgroud)

当我输入无效数量的宝石时,我收到此错误

线程"main"中的异常InvalidStartingStonesException:起始宝石的数量必须大于0且小于或等于10(尝试22)

为什么不是由我定义的throw处理的异常

KalaGame.<init>(KalaGame.java:27) at PlayKala.main(PlayKala.java:10)

java exception

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

无法在python中打印列表的内容

我创建了一个包含列表的类,其代码如下:

class ProdReg:
def __init__(self):
    self.__Pliste=[]
Run Code Online (Sandbox Code Playgroud)

这非常有效.我还添加了一个打印列表内容的方法:

def printProdReg(self):  
    for produkt in self.__Pliste:
        print(produkt)
Run Code Online (Sandbox Code Playgroud)

这并不是很好,当我尝试将对象添加到此列表时,我收到以下错误:

<__main__.Bok object at 0x05777970>
Run Code Online (Sandbox Code Playgroud)

该对象是一个名为的类Bok.

不知道我怎么能解决这个问题.

python

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

如何阻止外部访问的CSS

有人试图窃取我的css文件在他的网站上使用.我可以以某种方式阻止CSS文件从外部访问,但不会损坏我的网站?不知何故通过htaccess或其他东西.感谢您的建议,任何帮助表示感谢.

css .htaccess block

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

如何舍入到最近的50或100?

我有数字(十进制)我想将它舍入到"最接近的50":

  1. 122 =>舍入到150
  2. 177 =>舍入到200
  3. 157 =>舍入到200
  4. 57 =>舍入到100;
  5. 37 =>圆到50;
  6. 1557 =>舍入到1600
  7. 3537 =>轮到3550

如何用java/groovy做到这一点?

java groovy

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

将网站状态代码作为键返回的字典,将网站作为值返回 - py

嘿伙计我需要一些关于这个问题的指导(.py noobie)

所以我有一个具有不同状态代码的网站列表:

url_list=["http://www.ehow.com/foo-barhow_2323550_clean-coffee-maker-vinegar.html",
          "http://www.google.com",
          "http://livestrong.com/register/confirmation/",
          "http://www.facebook.com",
          "http://www.youtube.com"]
Run Code Online (Sandbox Code Playgroud)

我想要返回的是一个字典,它将网站的状态代码作为关键字返回,并将关联的网站作为值返回.像这样的东西:

result= {"200": ["http://www.google.com",
                 "http://www.facebook.com",
                 "http://www.youtube.com"], 
         "301": ["http://livestrong.com/register/confirmation/"],
         "404": ["http://www.ehow.com/foo-barhow_2323550_clean-coffee-maker-vinegar.html"]}
Run Code Online (Sandbox Code Playgroud)

我到现在为止:

获取状态代码的函数:

def code_number(url):
    try:
        u = urllib2.urlopen(url)
        code = u.code
    except urllib2.HTTPError, e:
        code = e.code
    return code
Run Code Online (Sandbox Code Playgroud)

一个函数应该返回字典但不工作 - 我被卡住的部分.基本上我不知道如何使它插入相同的状态代码超过1 url

result={}
def get_code(list_of_urls):
    for n in list_of_urls:
        code = code_number(n)
        if n in result:
            result[code] = n
        else:
            result[code] = n
    return result
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?!谢谢

python

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

在python中对列表进行排序的算法无法正常工作

我使用以下函数以按递增顺序对列表进行排序.但是,虽然我的函数适用于以下列表:[1,5,6,9,3]或者[56,43,16,97,45],它不适用于表单的列表:[20,10,1,3,50].

在这种情况下,计算机似乎认为3> 20和3> 10和3在我得到的"排序"列表中就在50(倒数第二个)之前结束.更准确地说,我得到的结果是:[1,10,20,3,50].

这是我的代码:

def function_sort(L):

    for j in range(len(L)):
        min=j
        for i in range(j+1,len(L)):
           if L[i]<L[min]:
              min = i

        if(min != j):
            L[j],L[min] = L[min],L[j]

            print L
    return L
Run Code Online (Sandbox Code Playgroud)

谁能请你解释一下发生了什么?

python

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

如何顺利打开div

请帮助我如何顺利打开 div。我添加了脚本和 html 代码,它工作正常,但 div 突然打开,突然出现混蛋。我想顺利打开我的 div "#mapsec"。

function showhide() {
    var div = document.getElementById("mapsec");
    if (div.style.display !== "none") {
        div.style.display = "none";
    }
    else {
        div.style.display = "block";

    }
}
Run Code Online (Sandbox Code Playgroud)

代码

<h3>Visit us (<i><a onclick="showhide()" id="scrollmap" class="mapimg" style="cursor: pointer;">Map</a></i>)</h3>

<div id="mapsec" style="display: none; clear: both;">
    <img
        src="http://www.websitesnmore.com.au/wp-content/uploads/2013/06/map-img.jpg"
        alt="map-img" width="1245" height="350"
        class="alignnone size-full wp-image-4586" />
</div>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

用Java语言对arraylist进行排序

我有一个arraylist设置.我也设置了输入设置,以便用户可以输入一个字符串,然后输入一个整数,然后输入一个字符串(名字,年龄和姓氏).

我需要用姓氏对arraylist进行排序.我到目前为止输入的代码都是主要方法: -

public static void main(String[] args) {
Name Name[] = new Name[50];
int count = 0;

for (int i=0; i<50; i++)
  NewName[i] = new Name();

//ADD NEW TO ARRAYLIST NAME
String FName = JOptionPane.showInputDialog("first name");
int age = Integer.parseInt(JOptionPane.showInputDialog("age"));
String LName = JOptionPane.showInputDialog("last name");
          NewName[count] = new Name(FName, age, LName);
count = count++;
}

//ITEMS SORT BY LAST NAME
//CODE FOR SORT GOES HERE
Run Code Online (Sandbox Code Playgroud)

java inputbox

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