This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class En06_02 { | |
public static void main(String[] args) { | |
//先頭が5なので、final変数で5を指定。 | |
final int MAX =5; | |
int[] a = new int[MAX]; | |
//for文で回しながら、結果も表示する。 | |
//配列変数.lengthで配列の長さを取得できる。 | |
for (int i = 0; i < a.length; i++) { | |
//MAXから配列のインデックス分減算する。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class En06_01 { | |
public static void main(String[] args) { | |
//ダブル型の配列を作成。要素数は5とする。 | |
double[] a = new double[5]; | |
//各要素に数値を代入。配列は0から始まる。 | |
a[0] = 0.0; | |
a[1] = 0.1; | |
a[2] = 0.2; | |
a[3] = 0.3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class En05_07 { | |
public static void main(String[] args) { | |
System.out.println(" float 2条 "); | |
System.out.println("---------------------"); | |
//xを求める。xを使用して2条を求める。 | |
for (float x = 0.0f; x <= 1.0f; x += 0.001f) { | |
System.out.printf("%.7f %.7f\n", x, (x * x)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class En05_06 { | |
public static void main(String[] args) { | |
System.out.println(" float int "); | |
System.out.println("---------------------"); | |
//xとyをインクリメントする。xの条件とyの条件が同じなので、 | |
//中央の式はxの条件だけで回す。※条件式は1つしかつけられない? | |
for (float x = 0.0f, y = 0.0f; x <= 1.0F; x += 0.001F, y++) { | |
//yを1000で割った値を変数へ入れる。 | |
float v = (float)y/1000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class En05_05 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
System.out.println("3つの整数値の合計と平均を計算します。"); | |
System.out.print("整数値a:"); | |
int a = stdIn.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class En05_04 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
System.out.println("3つの整数値の合計と平均を計算します。"); | |
System.out.print("整数値a:"); | |
int a = stdIn.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class En05_03 { | |
public static void main(String[] args){ | |
//boolean型の変数を作成。 | |
boolean tr = true; | |
boolean fl = false; | |
//出力 | |
System.out.println("tr = "+tr); | |
System.out.println("fl = "+fl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class En05_02 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
System.out.println("変数xはfloat型で、変数yはdouble型です。"); | |
System.out.print("x :"); | |
float x = stdIn.nextFloat(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class En05_01 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
System.out.print("整数値:"); | |
int n = stdIn.nextInt(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class En4_27 { | |
public static void main(String[] args) { | |
Random rand = new Random(); | |
Scanner stdIn = new Scanner(System.in); | |
// 最大回数を設定。 | |
final int MAX = 7; |