第4章字符串 H 41.2 String类的使用实例 在上一节中我们给出了 String类的一些方法,可以 看出, String类几乎覆盖了字符串的所有操作,给实际 的编程带来了极大的方便。下面我们给出一个 String类 的使用实例 例4.1 import java. awt. public class messages
第4章 字符串 4.1.2 String类的使用实例 在上一节中我们给出了String类的一些方法,可以 看出,String类几乎覆盖了字符串的所有操作,给实际 的编程带来了极大的方便。下面我们给出一个String类 的使用实例。 例4.1 import java.awt.*; public class Messages {
第4章字符串 H Allows messages to be sent to the class squarefigure via a dialog box public static void main (String[ args)i SquareFigure.created; while(true)&
第4章 字符串 /* Allows messages to be sent to the class SquareFigure via a dialog box. */ public static void main (String [ ] args) { SquareFigure.create(); while (true) { try {
⑤合、第4章字符串 H String message=Dialog Box. request ("Supply message to be sent Se quareFigure String message =message. trimo int startArg=message indexof(o int endArg=message indexof()) int commaPosn String argRaw, String arg String argl Raw; Stri ing arg String arg2raw
第4章 字符串 String message1 = DialogBox.request ("Supply message to be sent: ", "SquareFigure."); String message = message1.trim(); int startArg = message.indexOf('('); int endArg = message.indexOf(')'); int commaPosn; String argRaw; String arg; String arg1Raw; String arg1; String arg2Raw;
第4章字符串 H String arg2 String namel= message substring(o, startArg) /取出类中的方法 String name =namel trimo if(endArg-startArg>1)i argRaw= message substring(startArg-+l, endarg) 得到方法的调用参数 arg= arg Raw trimo else arg if(endArg =message length(-1)
第4章 字符串 String arg2; String name1 = message.substring(0, startArg); //取出类中的方法 String name = name1.trim(); if (endArg - startArg > 1) { argRaw = message.substring(startArg+1, endArg); //得到方法的调用参数 arg = argRaw.trim(); } else arg = ""; if (endArg != message.length() - 1)