Today did a teacher to give the first set of questions, the first question is to determine whether a string in another string: Do a bit, feel a good variety of writing, Java class really much ah, to master some of the basic class usage:
Package Com.exam.e120;public class Java1 {public static void main (String[]args) {String str1,str2;str1= ' I am Tom, I am from China. "; Str2= "Tom"; int i=str1.indexof (STR2);//The first method//if (Str1.contains (STR2))//The second method if (i!=-1) System.out.println ("\" "+ str2+ "\" is in the String:\ "" +str1+ "\" ") elseSystem.out.println (" \ "" +str2+ "\" was not in the String:\ "" +str1+ "\" ");}
This is just some of the most basic and simple questions, we can also accumulate some basic classes of usage from these problems, learning lies in the accumulation!
Here we use the string this class, can use inside of indexof this method, also can use contains this method;
IndexOf This method returns the position of the first occurrence of a string in another string (or possibly a character), and the output-1 (position starting from 0) is not found.
Contains this method to call it directly, see if the string contains another string (as if there are many classes inside this method, later encountered in the study).
The second problem is to print out the names of all the fonts in the current system; The problem is to call the method directly inside the class; Graphicsenvironment.getlocalgraphicsenvironment (). Getavailablefontfamilynames ();
Package Com.exam.e120;import Java.awt.graphicsenvironment;public class Java2 {public static void main (string[] args) { string[] FontNames = Graphicsenvironment.getlocalgraphicsenvironment (). Getavailablefontfamilynames (); for (int i = 0; i < Fontnames.length; i++) System.out.println (Fontnames[i]);}}
When we use a class that we haven't seen, it's a good practice to check the API documentation, and here we look at the API documentation.
API documentation is an official introduction, after watching we basically know how to use the class and method ~