關於我自己

我的相片
Welcome to discuss about : Chinese Traditional Medicine and Acupuncture Please send me the email: tccnchsu@gmail.com Chih-Yu Hsu

最新消息

總瀏覽量

2009年3月26日 星期四

Java 第六週

Java 第六週
上課錄影
http://www.powercam.cc/slide/1133
了解疊代法recursive()方法的用處,一種方法在自己的方法中呼叫自己這個方法。
void recursive(int a, int k, int n)
{
k=k+1;
if (k<=10)
recursive(a,k,n);
else
System.out.println("k="+k);

}

//
class Mysixthjava{
static String output = "";
public static void main(String args[]){
String InFileName,OutFileName;

try{

InFileName=args[0];//在執行時需要給檔名,例如 java Myfifthjava test.txt
System.out.print("Input File Name:" + InFileName + "\n" );
StringTokenizer tokens = new StringTokenizer( InFileName, ".t");;// 必須有".t"引數
File position = new File(InFileName);
OutFileName = tokens.nextToken() + ".w" + tokens.nextToken();
BufferedReader input = new BufferedReader(new FileReader( position ) );
int num = Integer.parseInt(input.readLine());
System.out.println(num);
File text = new File(OutFileName);
BufferedWriter output1 = new BufferedWriter(new FileWriter( text) );
output1.write(""+num);
output1.flush();
}catch(Exception e)
{
System.err.println(e);
}

}
}

class Addop
{
double x;
double y ;
public double z;

Addop()
{
x=1;
y=2;
z=x/y;
System.out.println("z="+z);
}
}

7 則留言:

歐地 提到...

//第六週作業 D9539125 黃培熏
import java.io.*;
import java.lang.Integer;

class HPS_006
{
public static void main(String[] args)
{
int num=0;
String inputtext = "";
try
{
File file=new File(args[0]);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
inputtext = br.readLine();
num = Integer.parseInt(inputtext);
}
catch(Exception e)
{
System.out.println("Error:"+e);
}
num=recursive(num);
inputtext=""+num;
try
{
File file=new File("hps_006out.txt");
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(inputtext);
bw.flush();
}
catch(Exception e)
{
System.out.println("Error:"+e);
}
}

static int recursive(int n)
{
if (n==1)
return 1;
else
return n*recursive(n-1);
}
}

靖文 提到...

/*第六周程式D9539108 陸靖文*/

import java.io.*;
import java.lang.Integer;


class FB02{

public static void main(String[] args) {
//filename01 = args[];
//System.out.println(args[0]);
int num=0;
String inputtext ="";

try {
File file01=new File(args[0]);
FileReader filereader01=new FileReader(file01);
BufferedReader bufferedreader01=new BufferedReader(filereader01);
inputtext = bufferedreader01.readLine();
num = Integer.parseInt(inputtext);
System.out.println("in="+inputtext);
} catch(Exception e) {
System.out.println("錯誤訊息: "+e);
}
num=recursive(num);
inputtext=""+num;
try {
File file02=new File(args[1]);
FileWriter filewrier01=new FileWriter(file02);
BufferedWriter bufferedwriter01=new BufferedWriter(filewrier01);
bufferedwriter01.write(inputtext);
bufferedwriter01.flush();
System.out.println("out="+num);

} catch(Exception e) {
System.out.println("錯誤訊息: "+e);
}

}
static int recursive(int k) {

if (k==1)
return 1;

else
return k*recursive(k-1);

}

}

黃鉦權 提到...

//D9582506 黃鉦權
import java.util.StringTokenizer;
import java.io.*;
import java.io.BufferedReader;
import java.lang.Integer;
//import java.io.File;

class Mysixthjava
{
public static void main(String[ ] args)
{
String inputtext="";
int num=0;
try{
//System.out.println(args[0]);
File myfile=new File(args[0]);
FileReader fr = new FileReader(myfile);
BufferedReader myBufferedReader=new BufferedReader(fr);
inputtext=myBufferedReader.readLine();
num=Integer.parseInt(inputtext);
}catch(Exception e)
{
System.out.println(e);
}
num=recursive(num);
inputtext=""+num;
try{
//System.out.println(args[0]);
File myfile=new File("5out.txt");
FileWriter fr = new FileWriter(myfile);
BufferedWriter myBufferedReader=new BufferedWriter(fr);
myBufferedReader.write(inputtext);
myBufferedReader.flush();

}catch(Exception e)
{
//System.out.println("Error:"+e);
}
}
static int recursive(int n)
{
if(n==0)
return 1;
else
return n*recursive(n-1);
}
}

d9538905 提到...

import java.io.*;
import java.lang.Integer;

class java06
{
public static void main(String[] args)
{
int v=1;
int num=1;
String a0="";
try
{

System.out.print("");
File file987=new File(args[0]);
FileReader re=new FileReader(file987);
BufferedReader bure=new BufferedReader(re);
a0=bure.readLine();
num = Integer.parseInt(a0);
}
catch(Exception e)
{
System.out.print("錯誤:"+ e);
}
num=recursive(num);
a0=""+num;
try
{
File fileout=new File("fileout01.txt");
FileWriter wr=new FileWriter(fileout);
BufferedWriter buwr=new BufferedWriter(wr);
buwr.write(a0);
buwr.flush();
}
catch(Exception e)
{
System.out.print("錯誤:"+ e);
}
}
static int recursive(int k)
{
if (k==1)
return 1;
else
return k*recursive(k-1);}
}

東東 提到...

d9746738 吳東翰



import java.util.StringTokenizer;
import java.io.*;
import java.io.BufferedReader;
import java.lang.Integer;
//import java.io.File;

class Mysixthjava
{
public static void main(String[ ] args)
{
String inputtext="";
int num=0;
try{
//System.out.println(args[0]);
File myfile=new File(args[0]);
FileReader fr = new FileReader(myfile);
BufferedReader myBufferedReader=new BufferedReader(fr);
inputtext=myBufferedReader.readLine();
num=Integer.parseInt(inputtext);
}catch(Exception e)
{
System.out.println(e);
}
num=recursive(num);
inputtext=""+num;
try{
//System.out.println(args[0]);
File myfile=new File("5out.txt");
FileWriter fr = new FileWriter(myfile);
BufferedWriter myBufferedReader=new BufferedWriter(fr);
myBufferedReader.write(inputtext);
myBufferedReader.flush();

}catch(Exception e)
{
//System.out.println("Error:"+e);
}
}
static int recursive(int n)
{
if(n==0)
return 1;
else
return n*recursive(n-1);
}
}

黃鉦權 提到...

//D9582506 黃鉦權
import java.util.StringTokenizer;
import java.io.*;
import java.io.BufferedReader;
import java.lang.Integer;
//import java.io.File;

class Mysixthjava
{
public static void main(String[ ] args)
{
String inputtext="";
int num=0;
try{
//System.out.println(args[0]);
File myfile=new File(args[0]);
FileReader fr = new FileReader(myfile);
BufferedReader myBufferedReader=new BufferedReader(fr);
inputtext=myBufferedReader.readLine();
num=Integer.parseInt(inputtext);
}catch(Exception e)
{
System.out.println(e);
}
num=recursive(num);
inputtext=""+num;
try{
//System.out.println(args[0]);
File myfile=new File("out.txt");
FileWriter fr = new FileWriter(myfile);
BufferedWriter myBufferedReader=new BufferedWriter(fr);
myBufferedReader.write(inputtext);
myBufferedReader.flush();

}catch(Exception e)
{
//System.out.println("Error:"+e);
}
}
static int recursive(int n)
{
if(n==0)
return 1;
else
return n*recursive(n-1);
}
}

提到...

D9377831 劉羽程
-----------------------------------
import java.io.*;
import java.lang.Integer;
class mysixthjava
{
public static void main (String[] args)
{
int num=0;
String inputtext="";
System.out.println(args[0]);
try{
File myfile=new File("930201.s01") ;
FileReader MyfileReader=new FileReader(myfile);
BufferedReader myBufferedReader = new BufferedReader(MyfileReader);
inputtext =myBufferedReader.readLine();
num = Integer.parseInt(inputtext);
}catch(Exception e)
{
System.out.println(e);
}
num=recursive(num);
inputtext=""+num;
try{
File myoutfile=new File("930201.ws01") ;
FileWriter MyfileWriter=new FileWriter(myoutfile);
BufferedWriter myBufferedWriter = new BufferedWriter(MyfileWriter);
myBufferedWriter.write(inputtext);
myBufferedWriter.flush();
}catch(Exception e)
{
System.out.println(e);
}
recursive(num);
}
static int recursive(int k)
{
System.out.println(k);
if (k==1)
return 1;
else
return k*recursive(k-1);
}
}