質問編集履歴

1

2015/05/18 14:36

投稿

qwerty123
qwerty123

スコア26

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,83 @@
27
27
 
28
28
 
29
29
  よろしくお願いします。
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+ 追記:
40
+
41
+ public class Square {
42
+
43
+ public static void main(String[] args) {
44
+
45
+
46
+
47
+ double square = 1; //最終的に2の平方根になる変数
48
+
49
+
50
+
51
+ double num = 1; //二乗の値の変数
52
+
53
+ while(true) {
54
+
55
+ square = num * num;
56
+
57
+
58
+
59
+
60
+
61
+ if(square > 2) {
62
+
63
+ num -= 0.0001;
64
+
65
+
66
+
67
+
68
+
69
+ }else{
70
+
71
+ num += 0.0001;
72
+
73
+ }
74
+
75
+
76
+
77
+
78
+
79
+ if( /*条件*/ ) {
80
+
81
+ break;
82
+
83
+ }
84
+
85
+ }
86
+
87
+
88
+
89
+ //少数第3位までを求める
90
+
91
+ double thousand = square * 1000;
92
+
93
+ double cast = (int)thousand;
94
+
95
+ double answer = cast / 1000;
96
+
97
+
98
+
99
+ System.out.println(answer);
100
+
101
+
102
+
103
+ }
104
+
105
+ }
106
+
107
+
108
+
109
+ 2の平方根を小数第三位まで求めるプログラムを作成しようと思いましたが、条件の定義がどうしてもよくわかりません。