- 1、本文档共47页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Exceptional Handling.ppt
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * String Tokenizer import?java.util.*;public?class?Strtok?{public?static?void?main(String?[]?args)?{????????String?Demo?=?This?is?a?string?that?we?want?to?tokenize;????????StringTokenizer?Tok?=?new?StringTokenizer(Demo);????????int?n=0;????????while?(Tok.hasMoreElements())????????System.out.println(?+?++n?+:?+Tok.nextElement());????????}}? * * String Tokenizer The following code reverses the order of words in a String. First it breaks the string into the words using StringTokenizer and reverses the order of the words using LIFO property of Stack. import?java.util.*;public?class?StringReverseWord?{private?static?void?doStringReverseWord()?{String?a?=?“Abu?Wang?Mang?Pang;Stack??stack?=?new?Stack();//?this?statement?will?break?the?string?into?the?words?which?are?separated?by?space.StringTokenizer?tempStringTokenizer?=?new?StringTokenizer(a);//?push?all?the?words?to?the?stack?one?by?onewhile?(tempStringTokenizer.hasMoreTokens())?{stack.push(tempStringTokenizer.nextElement());?}?System.out.println(\nOriginal?string:??+?a);System.out.print (Reverse?string:?);?????? * * String Tokenizer ??//?pop?the?words?from?the?stack????????while (!stack.empty())?{????????????System.out.print(stack.pop());????????????System.out.print(?);????????}????????System.out.println(\n);????}public?static?void?main(String[]?args)?{????????doStringReverseWord();????}} Output Screen: Original string: Abu?Wang?Mang?Pang Reverse string: Pang Mang Wang Abu * * String Tokenizer ??import java.io.*; import java.util.*; public class KeyboardReader { public static void main (String[] args) throws java.io.IOException { String s1; String s2; double num1, num2, product; // set up the buffered reader to read from the keyboard BufferedReader br = new BufferedReader (new InputStreamReader ( System.in)); System.out.println (Enter a line of input); s1 = br.readLine(); System.out.println (The line has + s1
文档评论(0)