люди... только начал учить!!... и еще ничего не знаю.. а дали задание.. уже всю голову сломал!!..
задание такое:
пользователь вводит любое число число...
надо посчитать сумму четных цифр... в числе.. если такие есть!!!
|
люди... только начал учить!!... и еще ничего не знаю.. а дали задание.. уже всю голову сломал!!..
задание такое:
пользователь вводит любое число число...
надо посчитать сумму четных цифр... в числе.. если такие есть!!!
x=parseInt(prompt("Input number","0"));
s=0;
while (x!=0)
{
c=x%10;
if (c%2==0) s=s+c;
x=x/10;
}
alert("Сумма четных цифр="+s);
почти!!!.. но не то... если ввести 122222... то выдает не 10 а 2.. ну и тд...
после первой найденой цифры цикл останавливается!
было пару ошибочек
<script>
x=Math.abs(parseInt(prompt("Input number","0")));
s=0;
while (x!=0)
{
c=x%10;
if (c%2==0)
s=s+c;
x=Math.floor(x/10);
}
alert("Сумма четных цифр="+s);
</script>
ух ...ты.. работает!!!... только что такое Math.floor, Math.abs??? я такое еще не учил
спасибо!!.. уже прочел ... что это такое!!..
Math.floor - округление до ближайшего меньшего целого
Math.abs - модуль
Спасибо большое!!..
думаю это не последний мой вопрос
а чем это можно заменить... ???
Math.floor
Math.abs
это я имею ввиду!!!
все... уже сам разобрался...
спасибо
Tower of Hanoi вот что нужно сделать на Java кто может помогите...
пожалуйста!!!
http://mamadu.ru/games/hanoi/index.htm - вот пример... с меня пиво
а если хотите пиво с рыбкой... то мне нужнен еще тенис.. самый приметивный.. на Java....
ну хоть помогите доделать!!... это тенис...
-----------------------
<html>
<head>
<title>Arkanoid</title>
<script type="text/javascript">
var w=400, h=700, dx=5, dy=5, x=100, y=0, count=1, m,a=0,b=0;
// dx, dy -- начальная скорость шарика
function moved()
{
d.style.left = parseInt(d.style.left) +a;
d.style.right = parseInt(d.style.right) +b;
if (parseInt(d.style.left)>375)
{
d.style.left=350;
}
if (parseInt(d.style.left)<25)
{
d.style.left=0;
}
}
function left()
{
a = -50;
b = 0;
}
function right()
{
a = 50;
b = 0;
}
function ShowKey(d)
{
if(d.keyCode==37)
left();
else if(d.keyCode==39)
right();
}
function movedtop()
{
d1.style.left = parseInt(d1.style.left) +a;
d1.style.right = parseInt(d1.style.right) +b;
if (parseInt(d1.style.left)>375)
{
d1.style.left=350;
}
if (parseInt(d1.style.left)<25)
{
d1.style.left=0;
}
}
function left()
{
a = -50;
b = 0;
}
function right()
{
a = 50;
b = 0;
}
function ShowKey(d1)
{
if(d1.keyCode==37)
left();
else if(d1.keyCode==39)
right();
}
function moveball()
{if (x+dx >= w-23 || x+dx <= 0)
dx = -dx;
if (y+dy < 0)
dy = -dy;
if (y+dy >= h-23 && x+dx+23 >= parseInt(d.style.left) && x+dx <= parseInt(d.style.left) + 50)
{
dy = -dy;
++count;
points.innerText='Points: '+(count-1);
if (count%2 == 1)
{
if(dx>0)
dx+=1;
else
dx-=1;
if(dy>0)
dy+=1;
else
dy-=1;
}
}
else if(y+dy >= h-0)
{
alert('гол!');
game();
}
x+=dx;
y+=dy;
ball.style.left = x;
ball.style.top = y;
}
function game()
{
w=400, h=700, dx=5, dy=5, x=100, y=0;
clearInterval(m);
m=setInterval('moveball();', 10)
}
</script>
</head>
<body onKeydown="ShowKey(event);moved();movedtop();" onload="game();">
<div id="points" style="position:absolute; background-color:silver; border:1 black solid; top:0; left:450;"></div>
<div style="position:absolute; background-color:silver; border:1 black solid; top:20; left:0; width:400; height:700;"></div>
<div id="d" style="position:absolute; background-color:red; border:1 black solid; top:720; left:0; width:50; height:3;"></div>
<div id="d1" style="position:absolute; background-color:red; border:1 black solid; top:0; left:0; width:50; height:3;"></div>
<img id="ball" style="position:absolute; top:0; left:100;" src="./08-28 img/nm.gif" alt="" >
</body>
</html>
Вот скрипт, посмотри
<html><head><style type="text/css">
#pongTable {
position: absolute;
top: 20px;
left: 20px;
width: 400px;
height: 300px;
border: 4px solid #CCC;
background-color: #F3F3F3;
z-index: 1;
}
#playerOne {
position: absolute;
top: 196px;
left: 45px;
width: 10px;
height: 35px;
background-color: #777;
z-index: 2;
}
#playerTwo {
position: absolute;
top: 196px;
left: 390px;
width: 10px;
height: 35px;
background-color: #777;
z-index: 2;
}
#ball {
position: absolute;
top: 160px;
left: 210px;
width: 7px;
height: 7px;
clip: rect(0px 7px 7px 0px);
background-color: #555;
z-index: 2;
display: none;
}
#click {
position: absolute;
top: 160px;
left: 27px;
width: 400px;
text-align: center;
font-family: Tahoma;
font-size: 10px;
z-index: 3;
}
#scores {
position: absolute;
top: 330px;
left: 24px;
width: 400px;
font-family: Tahoma;
font-size: 11px;
z-index: 3;
}
</style>
<script type="text/javascript">
var ballAng;
var speed = 3;
var ping = 5;
var pong = 0;
var mouseSpeed;
var tempY;
function init() {
document.getElementById("click").style.display = "none";
document.getElementById("ball").style.display = "inline";
with( document.getElementById("ball").style ) {
top = "160px";
left = "210px";
}
document.onmouseup = null;
document.onmousemove = movePaddle;
ballAng = Math.round( Math.random() * 100 ) + 130;
moveDaBall = setInterval("moveBall()", 10);
}
function movePaddle(e) {
e = (e)?e:event;
if( tempY ) {
mouseSpeed = Math.round((e.clientY - tempY) * 1.5);
if( mouseSpeed == 0 ) mouseSpeed = 1;
}
with( document.getElementById("playerOne").style ) {
top = e.clientY - 18 + "px";
if( parseInt(top) < 24 || parseInt(top) > 289 ) {
if( parseInt(top) < 24 ) {
top = "24px";
} else {
top = "289px";
}
}
}
tempY = e.clientY;
}
function moveBall() {
var ballX = parseInt(document.getElementById("ball").style.lef t);
var ballY = parseInt(document.getElementById("ball").style.top );
var playOneX = parseInt( document.getElementById("playerOne").style.left );
var playOneY = parseInt( document.getElementById("playerOne").style.top );
var playTwoX = parseInt( document.getElementById("playerTwo").style.left );
var playTwoY = parseInt( document.getElementById("playerTwo").style.top );
if( ballY >= (playOneY - 5) && ballY <= (playOneY + 35 + 5) && ballX >= playOneX && ballX <= (playOneX + 10) ) {
if( pong == 3 ) {
ping++;
pong = 0;
} else {
pong++;
}
document.getElementById("ball").style.left = playOneX + 10 + "px";
ballAng = 180 - ballAng - mouseSpeed;
}
if( ballY >= (playTwoY - 5) && ballY <= (playTwoY + 35 + 5) && ballX >= playTwoX && ballX <= (playTwoX + 10) ) {
if( pong == 3 ) {
ping++;
pong = 0;
} else {
pong++;
}
document.getElementById("ball").style.left = playTwoX + "px";
ballAng = 180 - ballAng;
}
if( ballY < 25 || ballY > 316 ) {
document.getElementById("ball").style.top = (ballY < 25)?25+"px":316+"px";
ballAng = 360 - ballAng;
}
if( ballX <= 24 || ballX >= 417 ) {
document.getElementById("ball").style.left = (ballX <=24)?24+"px":417+"px";
if( ballX<= 24 ) {
endPoint(document.getElementById("twoScore"));
} else {
endPoint(document.getElementById("oneScore"));
}
}
moveAI( ballY );
moveObjAtAngle( document.getElementById("ball"), ballAng, ping);
}
function moveObjAtAngle( obj, ang, dist ) {
with( obj.style ) {
left = parseInt(left) + ( dist * Math.cos( ang * (Math.PI/180) ) ) + "px";
top = parseInt(top) - ( dist * Math.sin( ang * (Math.PI/180) ) ) + "px";
}
}
function moveAI( y ) {
var AI = document.getElementById("playerTwo");
y = y - 10;
y = parseInt(AI.style.top) + ((y - parseInt(AI.style.top)) / speed);
if( y < 24 || y > 289 ) {
if( y < 24 ) {
y = 24;
} else {
y = 289;
}
}
AI.style.top = y +"px";
}
function endPoint(place) {
clearInterval(moveDaBall);
ping = 7;
pong = 0;
document.onmouseup = init;
document.getElementById("click").innerHTML = "click to continue";
place.innerHTML = parseInt(place.innerHTML) + 1;
if( parseInt(place.innerHTML) == 10 ) {
if( place.id == "oneScore" ) {
endGame(1);
} else {
endGame(0);
}
}
document.getElementById("click").style.display = "inline";
}
function endGame(win) {
document.onmouseup = restartGame;
if( win ) {
document.getElementById("click").innerHTML = "<strong>you are dah winnah!</strong><br /> click to start over";
} else {
document.getElementById("click").innerHTML = "<strong>you are dah losah!</strong><br /> click to start over";
}
}
function restartGame() {
document.getElementById("oneScore").innerHTML = 0;
document.getElementById("twoScore").innerHTML = 0;
init();
}
document.onmouseup = init;
</script>
</head><body>
<div id="pongTable">
<div style="float: right; width: 50%; height: 100%; border-left: 2px dashed #DDD;"> </div>
</div>
<div id="playerOne" style="left: 45px; top: 146px"> </div>
<div id="playerTwo" style="left: 390px; top: 146px"> </div>
<div id="ball" style="left: 210px; top: 160px"> </div>
<div id="click">click to continue</div>
<div id="scores">
<span style="float: left;" id="oneScore">0</span>
<span style="float: right;" id="twoScore">0</span>
</div>
</body></html>
Социальные закладки