package xmlpro0708;
public class SampleSort_for {
public static void main(String[] args) {
int[] test = { 32, 16, 48, 24, 79 };
for (int t = 0; t < test.length - 1; t++) {
for (int s = t + 1; s < test.length; s++) {
if (test[t] > test[s]) {
int tmp = test[t];
test[t] = test[s];
test[s] = tmp;
}
}
}
}
}
public class Sort_for {
public static void main(String[] args) {
int[] test = { 32, 16, 48, 24, 79 };
System.out.println("ソート前");
System.out.print("test = {");
for (int i = 0; i < test.length; i++) {
System.out.print(test[i] + ",");
}
System.out.println("}");
System.out.println("-------------------------------");
for (int t = 0; t < test.length - 1; t++) {
System.out.println((t + 1) + "番目に小さい数を配列の" + (t + 1) + "番目に移動します");
for (int s = t + 1; s < test.length; s++) {
if (test[t] > test[s]) {
System.out.print("○");
System.out.print("test[" + t + "] = " + test[t]);
System.out.print(" > ");
System.out.print("test[" + s + "] = " + test[s]);
int tmp = test[t];
test[t] = test[s];
test[s] = tmp;
System.out.print(" 交換します ");
}
System.out.print("test[" + t + "] = " + test[t]);
System.out.print(" > ");
System.out.println("test[" + s + "] = " + test[s]);
}
System.out.println("ループ t: " + (t + 1) + "回目の処理後の配列");
System.out.print("test = {");
for (int i = 0; i < test.length; i++) {
System.out.print(test[i] + ",");
}
System.out.println("}
");
}
System.out.println("ソート後");
System.out.println("-------------------------------");
System.out.print("test = {");
for (int i = 0; i < test.length; i++) {
System.out.print(test[i] + ",");
}
System.out.println("}");
}
}
package xmlpro0708;
public class ScopeDog {
public static void main(String[] args) {
if(1 == 1) {
int t = 5;
System.out.println(t);
}
System.out.println(t);
}
}
package xmlpro0708;
public class ScopeDog {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println(i);
}
System.out.println(i);
}
}
package xmlpro0708;
public class ScopeDog {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
int t = 5;
System.out.println(i);
}
System.out.println(t);
}
}
package xmlpro0708;
public class Hiroimono {
public static void main(String[] args) {
int y = 30;
//メソッド呼び出し
method(y);
System.out.println("----main()------");
System.out.println("main() y: " + y);
}
static void method(int y) {
y *= 10;
System.out.println("----method()----");
System.out.println("method() y: " + y);
}
}
package xmlpro0708;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FileReader_verScanner {
public static void main(String[] args) {
try {
File file = new File("FIles\Icpc2006_A.txt");
Scanner scan = new Scanner(file);
scan.useDelimiter("¥¥r¥¥n");
while (scan.hasNext()) {
String str = scan.next();
System.out.println(str);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
}
}
package xmlpro0708;
public class Bunkatu {
public static void main(String[] args) {
String str = "afaf fdkfka sss344 433";
/*配列を用意して文字列に対してsplit()メソッドを
* 実行すると自動で配列に代入してくれます
*/
String[] str2 = str.split(" ");
for (int i = 0; i < str2.length; i++) {
System.out.println(str2[i]);
}
}
}