| 目次| 1234567891011121314
| 資料| 予定| 課題| 宿題|

プログラムリスト

Calc1.java

public class Calc1 {
    public static void main(String args[]) {
        System.out.print("加算の結果は");
        System.out.print(3+2);
        System.out.println("です.");
	
	System.out.print("減算の結果は");
        System.out.print(5-8);
        System.out.println("です.");
	
	System.out.print("乗算の結果は");
        System.out.print(3*4);
        System.out.println("です.");
	
	System.out.print("徐算の結果は");
        System.out.print(7/3);
        System.out.println("です.");
	
    }
}

Calc2.java

public class Calc2 {
    public static void main(String args[]) {
        System.out.print("演算の結果は");
        System.out.print(1+2*3-4/2);
        System.out.println("です.");
    }
}

Calc3.java

public class Calc3 {
    public static void main(String args[]) {
        System.out.print("演算の結果は");
        System.out.print(((1+2)*3-5)/2);
        System.out.println("です.");
    }
}

Calc4.java

public class Calc4 {
    public static void main(String args[]) {
        System.out.println("加算の結果は"+3+2+"です.");
    }
}

Var1.java

public class Var1 {
   public static void main(String[] args) {
      int x;
      x = 5;
      System.out.println(x * x);
   }
}

Var2.java

public class Var2 {
   public static void main(String[] args) {
      double x = 15;
      double y = 32;
      System.out.print("演算の結果は");
      System.out.print((x+y)/2);
      System.out.println("です.");
   }
}

Var3.java

public class Var3 {
    public static void main(String args[]) {
	int x = 33;
	int y = 16;
	
        System.out.print("xの値は");
        System.out.print(x);
        System.out.println("です.");
	
        System.out.print("yの値は");
        System.out.print(y);
        System.out.println("です.");

	x = y ;
	y = x ;
	
        System.out.print("xの値は");
        System.out.print(x);
        System.out.println("です.");
	
        System.out.print("yの値は");
        System.out.print(y);
        System.out.println("です.");
	
    }
}

KeyboardInput.java

// キーボードからの入力を扱う 
import java.io.*;

class KeyboardInput {
    
    static int askInt(String message) {
        try {
            System.out.print(message);
            System.out.flush();
            String line =
                   new BufferedReader(new InputStreamReader(System.in),1).readLine();
            return Integer.parseInt(line);
        } catch (IOException e) {
            System.out.println("入力を扱えません");
            return 0;
	} catch (NumberFormatException e) {
	    System.out.println("数字ではありません");
	    return 0;
	}
    }

    static long askLong(String message) {
        try {
            System.out.print(message);
            System.out.flush();
            String line =
                   new BufferedReader(new InputStreamReader(System.in),1).readLine();
            return Long.parseLong(line);
        } catch (IOException e) {
            System.out.println("入力を扱えません");
            return 0;
	} catch (NumberFormatException e) {
	    System.out.println("数字ではありません");
	    return 0;
	}
    }

    static double askDouble(String message) {
        try {
            System.out.print(message);
            System.out.flush();
            String line =
                   new BufferedReader(new InputStreamReader(System.in),1).readLine();
            return Double.valueOf(line).doubleValue();
        } catch (IOException e) {
            System.out.println("入力を扱えません");
            return Double.NaN;
	} catch (NumberFormatException e) {
	    System.out.println("数字ではありません");
	    return Double.NaN;
	}
    }
    
    static String askString(String message) {
        try {
            System.out.print(message);
            System.out.flush();
            return new BufferedReader(new InputStreamReader(System.in),1).readLine();
        } catch (IOException e) {
            System.out.println("入力を扱えません");
            return null;
	}
    }
}

HowOldAreYou.java

public class HowOldAreYou {
    public static void main(String args[]) {
	//String型(文字列を格納できる)の変数 name の宣言
	String name;

	//「お名前は?」と表示し,入力内容を name に保存
	name = KeyboardInput.askString("お名前は?");

	//挨拶を表示
	System.out.print("こんにちは,");
	System.out.print(name);
	System.out.println("さん.");

	//int型の変数 age の宣言
	int age;

	//年齢を尋ね,ageに保存
	age = KeyboardInput.askInt("年齢を入力してください.");

	//教える
	System.out.print(name);
	System.out.print("さん,");
	System.out.print("いま");
	System.out.print(age);
	System.out.print("歳とすると,10年後は");
	System.out.print(age+10);
	System.out.println("歳ですね.");	
    }
}

SimpleAnimation.java

import java.applet.Applet;
import java.awt.*;
/*
<APPLET CODE="SimpleAnimation.class" WIDTH=100 HEIGHT=100>
<PARAM NAME="imagedir"    VALUE="images">
<PARAM NAME="imageprefix" VALUE="snow">
<PARAM NAME="last"        VALUE="6">
</APPLET>
*/
public class SimpleAnimation extends Applet implements Runnable {
    String imagedir;
    String imageprefix;
    int last;
    Image images[];
    int current;
    Thread thread;

    public void init() {
        String s;
        s = getParameter("imagedir");
        if (s != null) imagedir = s;
        s = getParameter("imageprefix");
        if (s != null) imageprefix = s;
        s = getParameter("last");
        if (s != null) last = Integer.parseInt(s);

        current = 0;
        images = new Image[last];
        for (int i = 0; i < last; i++) {
            images[i] =
                getImage(getDocumentBase(),
                    imagedir + "/" + imageprefix + (i+1) + ".gif");
        }
    }

    public void start() {
        if (thread == null) {
            thread = new Thread(this);
            thread.start();
        }
    }

    public void paint(Graphics g) {
        g.drawImage(images[current], 0, 0, this);
    }

    public void run() {
        while(true) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                break;
            }
            current++;
            if (current == last) current = 0;
            repaint();
        }
    }
}

HelloWorld.java

import java.applet.Applet;
import java.awt.Graphics;
/*
<applet code="HelloWorld" width=200 height=100></applet>
*/

public class HelloWorld extends Applet {
	public void paint(Graphics g){
	  
		g.drawString("Hello World!", 50, 25);
	}
}

| 目次| 1234567891011121314
| 資料| 予定| 課題| 宿題| Last modified: Wed Oct 12 13:46:17 JST 2016