import java.io.*;
public class test12{
public static void main(String[] args)throws IOException {
BufferedReader input = new BufferedReader
(new InputStreamReader(System.in));
char c;
int c_total=0,num_total=0;
do
{
System.out.print("請輸入字元: ");
c=(char)input.read();
input.skip(2);
if(Character.isDigit(c))
num_total+=1;
else
c_total+=1;
while(true)
{
System.out.print("請問是否還要繼續輸入(Y/N): ");
c=(char)input.read();
input.skip(2);
if((c=='Y')||(c=='y')||(c=='N')||(c=='n'))
break;
}
}while((c=='Y')||(c=='y'));
System.out.println("您輸入的數字有"+num_total+"次");
System.out.println("您輸入的字有"+c_total+"次");
}
}
- Apr 18 Wed 2007 19:10
<Java-基礎篇>流程控制11-計算使用者輸入字母或數字次數(do-while)
close
全站熱搜
留言列表