Практикум по программированию. Основы. Ветвление. Поле сферы
From AsIsWiki
(Difference between revisions)
Line 17: | Line 17: | ||
System.out.println(); | System.out.println(); | ||
− | System.out.println(" | + | System.out.println("Расчет напряженности электростатического поля сферы"); |
− | + | System.out.println("---------------------------------------------------"); | |
− | System.out.println("--------------------------------"); | + | |
System.out.print(" Введите заряд сферы: "); | System.out.print(" Введите заряд сферы: "); | ||
Line 30: | Line 29: | ||
double l = in.nextDouble(); | double l = in.nextDouble(); | ||
− | System.out.println("--------------------------------"); | + | System.out.println("---------------------------------------------------"); |
double e = l < r ? 0 : q / (l * l); | double e = l < r ? 0 : q / (l * l); | ||
Line 53: | Line 52: | ||
double q, r, l; | double q, r, l; | ||
− | cout << "\ | + | cout << "\nРасчет напряженности электростатического поля сферы\n"; |
− | + | cout << "---------------------------------------------------\n"; | |
− | cout << "--------------------------------\n"; | + | |
cout << " Введите заряд сферы: "; | cout << " Введите заряд сферы: "; | ||
Line 66: | Line 64: | ||
cin >> l; | cin >> l; | ||
− | cout << "--------------------------------\n"; | + | cout << "---------------------------------------------------\n"; |
double e = l < r ? 0 : q / (l * l); | double e = l < r ? 0 : q / (l * l); | ||
Line 86: | Line 84: | ||
<source lang="js"> | <source lang="js"> | ||
+ | <html lang="ru"> | ||
+ | <head> | ||
+ | <meta charset="UTF-8"> | ||
+ | <script> | ||
+ | function calc() { | ||
+ | var q = document.getElementById("qId").value; | ||
+ | var r = document.getElementById("rId").value; | ||
+ | var l = document.getElementById("lId").value; | ||
+ | |||
+ | var e = l < r ? 0 : q / (l * l); | ||
+ | |||
+ | document.getElementById("resultId").innerHTML = | ||
+ | "Напряженность поля E = " + e.toFixed(2) + " в/м"; | ||
+ | } | ||
+ | </script> | ||
+ | </head> | ||
+ | <body> | ||
+ | |||
+ | <p>Расчет напряженности электростатического поля сферы</p> | ||
+ | <hr> | ||
+ | <p>Введите заряд сферы: <input id="qId" size="5"></p> | ||
+ | <p>Введите радиус сферы: <input id="rId" size="5"></p> | ||
+ | <p>Расстояние от центра сферы до исследуемой точки: <input id="lId" size="5"></p> | ||
+ | <hr> | ||
+ | <p id="resultId"></p> | ||
+ | |||
+ | <button onclick="calc()">Рассчитать</button> | ||
+ | |||
+ | </body> | ||
+ | </html> | ||
</source> | </source> | ||
Revision as of 12:44, 17 March 2016
Contents |
Java
import java.util.Scanner; public class Task17 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println(); System.out.println("Расчет напряженности электростатического поля сферы"); System.out.println("---------------------------------------------------"); System.out.print(" Введите заряд сферы: "); double q = in.nextDouble(); System.out.print(" Введите радиус сферы: "); double r = in.nextDouble(); System.out.print(" Расстояние от центра сферы до исследуемой точки: "); double l = in.nextDouble(); System.out.println("---------------------------------------------------"); double e = l < r ? 0 : q / (l * l); System.out.printf(" Напряженность поля E = %.2f в/м\n", e); } }
C++
// g++ 4.2 #include <iostream> using namespace std; int main() { double q, r, l; cout << "\nРасчет напряженности электростатического поля сферы\n"; cout << "---------------------------------------------------\n"; cout << " Введите заряд сферы: "; cin >> q; cout << " Введите радиус сферы: "; cin >> r; cout << " Расстояние от центра сферы до исследуемой точки: "; cin >> l; cout << "---------------------------------------------------\n"; double e = l < r ? 0 : q / (l * l); printf(" Напряженность поля E = %.2f в/м\n\n", e); return 0; }
Pascal
JavaScript
<html lang="ru"> <head> <meta charset="UTF-8"> <script> function calc() { var q = document.getElementById("qId").value; var r = document.getElementById("rId").value; var l = document.getElementById("lId").value; var e = l < r ? 0 : q / (l * l); document.getElementById("resultId").innerHTML = "Напряженность поля E = " + e.toFixed(2) + " в/м"; } </script> </head> <body> <p>Расчет напряженности электростатического поля сферы</p> <hr> <p>Введите заряд сферы: <input id="qId" size="5"></p> <p>Введите радиус сферы: <input id="rId" size="5"></p> <p>Расстояние от центра сферы до исследуемой точки: <input id="lId" size="5"></p> <hr> <p id="resultId"></p> <button onclick="calc()">Рассчитать</button> </body> </html>