2010年6月11日 星期五

期末考

import java.io.*;import java.util.*;import java.lang.String;class Fin{
public static void main(String args[]){String filename;String data;int i,j;int [][] a=new int [2][2];int [][] b=new int [2][2];int [][] c=new int [2][2];
try{filename=args[0];FileReader fr=new FileReader(filename);BufferedReader br=new BufferedReader(fr);
FileWriter fw=new FileWriter("output.txt");BufferedWriter bw=new BufferedWriter(fw);
for(i=0;i<2;i++){data=br.readLine();StringTokenizer tokens=new StringTokenizer(data,",");for(j=0;j<2;j++){a[i][j]=Integer.parseInt(tokens.nextToken());}}
for(i=0;i<2;i++){data=br.readLine();StringTokenizer tokens=new StringTokenizer(data,",");for(j=0;j<2;j++){b[i][j]=Integer.parseInt(tokens.nextToken());}}
for(i=0;i<2;i++){System.out.print("[");bw.write("[");for(j=0;j<2;j++){c[i][j]=a[i][j]+b[i][j];System.out.print(" "+c[i][j]+" ");bw.write(" "+c[i][j]+" ");}System.out.print("]\r\n");bw.write("]\r\n");}
bw.flush();bw.close();} // The end of try
catch(Exception e){System.out.println("exception");}
} // The end of main
} // The end of class

2010年6月3日 星期四

期末心得

本學期修了許老師的JAVA課程,剛開始感覺很簡單也覺得很有趣。老師的教學方式也是很好的方法。從錯誤中學習,可以讓同樣的錯誤不會再犯錯!

2010年4月9日 星期五

JAVA 作業4/9

class calcArea{
public static void main(String[] args)
{
int a,b;
double triArea,rectArea;
String s1,s2;
s1=args[0];
s2=args[1];

Triangle calcTri = new Triangle();
triArea = calcTri.calc(s1,s2);

Rectangle calcRect = new Rectangle();
rectArea = calcRect.calc(s1,s2);

System.out.println("長 = "+s1);
System.out.println("高 = "+s2);
System.out.println("三角形面積 = "+triArea);
System.out.println("長方形面積 = "+rectArea);
}}

class Triangle{
Triangle()
{
//System.out.println("三角形面積");
}

static int calc(String s1, String s2){
int x,y,z;
x = Integer.parseInt(s1);
y = Integer.parseInt(s2);
z = x * y /2;
return z;
}}

class Rectangle{
Rectangle()
{
//System.out.println("長方形面積");
}

static int calc(String s1, String s2)
{
int x,y,z;
x = Integer.parseInt(s1);
y = Integer.parseInt(s2);
z = x * y;
return z;
}}

2010年3月26日 星期五

JAVA 作業

class add
{
public static void main(String[]args)
{
String x,y;
int z=0;
x=args[0];
y=args[1];
z=Integer.parseInt(args[0])+Integer.parseInt(args[1]);
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
}

2010年1月7日 星期四

java



using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
namespace WindowsFormsApplication1{ public partial class Form1 : Form { int[] score = new int [10]; int temp,temps; public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { score[0] = 0; score[1] = 1; score[2] = 2; score[3] = 3; score[4] = 4; score[5] = 5; score[6] = 6; score[7] = 7; score[8] = 8; }
private void button1_Click(object sender, EventArgs e) { if (Convert.ToInt16(button2.Text) == 0) { temps = Convert.ToInt16(button2.Text); button2.Text = Convert.ToString(button1.Text); button1.Text=Convert.ToString(temps); }
if (Convert.ToInt16(button4.Text) == 0) { temps = Convert.ToInt16(button4.Text); button4.Text = Convert.ToString(button1.Text); button1.Text = Convert.ToString(temps); } }
private void button2_Click(object sender, EventArgs e) { if (Convert.ToInt16(button1.Text) == 0) { temps = Convert.ToInt16(button1.Text); button1.Text = Convert.ToString(button2.Text); button2.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button3.Text) == 0) { temps = Convert.ToInt16(button3.Text); button3.Text = Convert.ToString(button2.Text); button2.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button5.Text) == 0) { temps = Convert.ToInt16(button5.Text); button5.Text = Convert.ToString(button2.Text); button2.Text = Convert.ToString(temps); } }
private void button3_Click(object sender, EventArgs e) { if (Convert.ToInt16(button2.Text) == 0) { temps = Convert.ToInt16(button2.Text); button2.Text = Convert.ToString(button3.Text); button3.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button6.Text) == 0) { temps = Convert.ToInt16(button6.Text); button6.Text = Convert.ToString(button3.Text); button3.Text = Convert.ToString(temps); } }
private void button4_Click(object sender, EventArgs e) { if (Convert.ToInt16(button1.Text) == 0) { temps = Convert.ToInt16(button1.Text); button1.Text = Convert.ToString(button4.Text); button4.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button5.Text) == 0) { temps = Convert.ToInt16(button5.Text); button5.Text = Convert.ToString(button4.Text); button4.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button7.Text) == 0) { temps = Convert.ToInt16(button7.Text); button7.Text = Convert.ToString(button4.Text); button4.Text = Convert.ToString(temps); } }
private void button5_Click(object sender, EventArgs e) { if (Convert.ToInt16(button2.Text) == 0) { temps = Convert.ToInt16(button2.Text); button2.Text = Convert.ToString(button5.Text); button5.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button4.Text) == 0) { temps = Convert.ToInt16(button4.Text); button4.Text = Convert.ToString(button5.Text); button5.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button6.Text) == 0) { temps = Convert.ToInt16(button6.Text); button6.Text = Convert.ToString(button5.Text); button5.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button8.Text) == 0) { temps = Convert.ToInt16(button8.Text); button8.Text = Convert.ToString(button5.Text); button5.Text = Convert.ToString(temps); } }
private void button6_Click(object sender, EventArgs e) { if (Convert.ToInt16(button3.Text) == 0) { temps = Convert.ToInt16(button3.Text); button3.Text = Convert.ToString(button6.Text); button6.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button5.Text) == 0) { temps = Convert.ToInt16(button5.Text); button5.Text = Convert.ToString(button6.Text); button6.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button9.Text) == 0) { temps = Convert.ToInt16(button9.Text); button9.Text = Convert.ToString(button6.Text); button6.Text = Convert.ToString(temps); } }
private void button7_Click(object sender, EventArgs e) { if (Convert.ToInt16(button4.Text) == 0) { temps = Convert.ToInt16(button4.Text); button4.Text = Convert.ToString(button7.Text); button7.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button8.Text) == 0) { temps = Convert.ToInt16(button8.Text); button8.Text = Convert.ToString(button7.Text); button7.Text = Convert.ToString(temps); } }
private void button8_Click(object sender, EventArgs e) { if (Convert.ToInt16(button5.Text) == 0) { temps = Convert.ToInt16(button5.Text); button5.Text = Convert.ToString(button8.Text); button8.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button7.Text) == 0) { temps = Convert.ToInt16(button7.Text); button7.Text = Convert.ToString(button8.Text); button8.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button9.Text) == 0) { temps = Convert.ToInt16(button9.Text); button9.Text = Convert.ToString(button8.Text); button8.Text = Convert.ToString(temps); } }
private void button9_Click(object sender, EventArgs e) { if (Convert.ToInt16(button6.Text) == 0) { temps = Convert.ToInt16(button6.Text); button6.Text = Convert.ToString(button9.Text); button9.Text = Convert.ToString(temps); }
if (Convert.ToInt16(button8.Text) == 0) { temps = Convert.ToInt16(button8.Text); button8.Text = Convert.ToString(button9.Text); button9.Text = Convert.ToString(temps); } } private void button10_Click(object sender, EventArgs e) { randoms_run();
button10.BackColor = Color.White; }
private void randoms_run() { randoms(); random_Color(button1, temp); button1.Text = Convert.ToString(temp); randoms(); random_Color(button2, temp); button2.Text = Convert.ToString(temp); randoms(); random_Color(button3, temp); button3.Text = Convert.ToString(temp); randoms(); random_Color(button4, temp); button4.Text = Convert.ToString(temp); randoms(); random_Color(button5, temp); button5.Text = Convert.ToString(temp); randoms(); random_Color(button6, temp); button6.Text = Convert.ToString(temp); randoms(); random_Color(button7, temp); button7.Text = Convert.ToString(temp); randoms(); random_Color(button8, temp); button8.Text = Convert.ToString(temp); randoms(); random_Color(button9, temp); button9.Text = Convert.ToString(temp); } private void randoms() { for (int i = 0; i <= 8; i++) { Random rd = new Random(); int myrnd = rd.Next(0, 7); temp = score[myrnd]; score[myrnd] = score[i]; score[i] = temp; } } private void random_Color(Button temp_btn, int temp_color) { switch (temp_color) { case 0: temp_btn.BackColor = Color.Blue; break; case 1: temp_btn.BackColor = Color.Pink; break; case 2: temp_btn.BackColor = Color.Yellow; break; case 3: temp_btn.BackColor = Color.Green; break; case 4: temp_btn.BackColor = Color.Red; break; case 5: temp_btn.BackColor = Color.Purple; break; case 6: temp_btn.BackColor = Color.Orange; break; case 7: temp_btn.BackColor = Color.Gray; break; case 8: temp_btn.BackColor = Color.White; break; } } }}