Le nombre de jonquilles dans la boucle for petit exercice en JavaScript

Que sont les jonquilles ? ?

Jonquille : Un nombre de jonquille est un nombre à 3 chiffres dont la somme à la puissance 3 dans chaque chiffre est égale à elle-même, par exemple : abc=a *a *a+b * b* b+c* c *c

Table des matières

Première étape : le cadre

La deuxième étape: analyse, tout d'abord, nous pouvons savoir que la jonquille est un nombre à 3 chiffres selon le titre, nous pouvons donc obtenir une condition de jugement selon laquelle il est supérieur à 100 et inférieur à 1000

Étape 3 : Si nous voulons effectuer un type d'opération de jugement ici, la prémisse est de savoir si nous voulons obtenir les centaines, les dizaines et les unités, donc le code ci-dessus

Étape 4 : Les dix

Étape 5 : Unités

Étape 6 : Jugement

Étape 7 : Continuez à juger

Étape 8 : Sortie

Enfin : code complet


 

 

Première étape : le cadre

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			
		</script>
	</body>
</html>

La deuxième étape: analyse, tout d'abord, nous pouvons savoir que la jonquille est un nombre à 3 chiffres selon le titre, nous pouvons donc obtenir une condition de jugement selon laquelle il est supérieur à 100 et inférieur à 1000

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			
			for (var i = 100; i <= 1000; i++) {
				}







			
		</script>
	</body>
</html>

Étape 3 : Si nous voulons effectuer un type d'opération de jugement ici, la prémisse est de savoir si nous voulons obtenir les centaines, les dizaines et les unités, donc le code ci-dessus est utilisé pour opérer

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				
				}
			
		
		
		</script>
	</body>
</html>

S'il y a un parsenint ici, la fonction est d'arrondir, c'est-à-dire 3,5 = 3. Ensuite, nous trouverons la méthode à dix chiffres.

Étape 4 : Les dix

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				
		
		</script>
	</body>
</html>

 Parsenint est également utilisé ici, et un reste est%, par exemple 153% 10 = 53, donc ici nous obtenons un nombre à deux chiffres, puis divisons par 10, nous obtenons 5,3, puis arrondissons à 5, la demande suivante pour un endroit

Étape 5 : Unités

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				// 求个位
				var c = parseInt(i % 10);
				
		
		</script>
	</body>
</html>

 Si le chiffre un est le reste de 10, par exemple, 153 % 10 = 3, puis un autre tour sera ajouté. De cette façon, nous obtiendrons le chiffre un, le chiffre des dizaines et le chiffre des centaines, de sorte que nous pouvons faire un jugement ensuite.

Étape 6 : Jugement

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				// 求个位
				var c = parseInt(i % 10);
				// Math.pow代表web里的一个数学函数,即a的3次方
				if (Math.pow(a, 3) ) {
				
		
		</script>
	</body>
</html>

 Une fonction est utilisée ici. Math.pow représente une fonction mathématique sur le Web, c'est-à-dire la troisième puissance de a. Vous pouvez également écrire a**a

Étape 7 : Continuez à juger

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				// 求个位
				var c = parseInt(i % 10);
				// Math.pow代表web里的一个数学函数,即a的3次方
				if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == i) {
					
		
		</script>
	</body>
</html>

Étape 8 : Sortie

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				// 求个位
				var c = parseInt(i % 10);
				// Math.pow代表web里的一个数学函数,即a的3次方
				if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == i) {
					count++
					console.log(i);

				}
			}
			console.log(count);
		
		</script>
	</body>
</html>

Enfin : code complet

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				// 求个位
				var c = parseInt(i % 10);
				// Math.pow代表web里的一个数学函数,即a的3次方
				if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == i) {
					count++
					console.log(i);

				}
			}
			console.log(count);
		
		</script>
	</body>











</html>














<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			var count = 0;
			// var num = i;
			for (var i = 100; i <= 1000; i++) {
				// 求百位
				var a = parseInt(i / 100);
				// 求十位
				var b = parseInt((i % 100) / 10);
				// 求个位
				var c = parseInt(i % 10);
				// Math.pow代表web里的一个数学函数,即a的3次方
				if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == i) {
					count++
					console.log(i);

				}
			}
			console.log(count);







		</script>
	</body>
</html>

 

Je suppose que tu aimes

Origine blog.csdn.net/tea_tea_/article/details/126272489
conseillé
Classement