|
|
Исходный текст программы
StringDemo.java
|
Оглавление |
Назад
// =======================================
// StringDemo.java
//
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// =======================================
import java.io.*;
import java.util.*;
public class StringDemo
{
public static void main(String args[])
{
byte bKbd[] = new byte[256];
StringTokenizer st;
int iCnt = 0;
char[] chArray = {'*', 'A', 'B', 'C', '*'};
String szStr = String.copyValueOf(chArray);
System.out.println("szStr = " + szStr);
while(true)
{
System.out.println(
"\nEnter string ('end' to terminate):\n");
try
{
iCnt = System.in.read(bKbd);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
szStr = new String(bKbd, 0, iCnt);
st = new StringTokenizer(szStr, "\r\n");
szStr =
new String((String)st.nextElement());
if(szStr.compareTo("end") == 0)
{
System.out.println("\nEnd");
break;
}
else if(szStr.endsWith("***"))
{
System.out.println("Stars ***");
}
else if(szStr.startsWith("---"))
{
System.out.println("Minus ---");
}
else if(szStr.indexOf("+++") != -1)
{
System.out.println("Plus +++");
}
else
{
szStr = "<<<" + szStr.concat(">>>");
System.out.println("szStr = " + szStr);
szStr = szStr.toLowerCase();
System.out.println("Lower case szStr = "
+ szStr);
}
}
}
}
Назад |
|
|