请问一个简单的问题,这里的say $+$getnumber表示什么意思?

hugoon 2007-04-23 03:31:04
if (s.endsWith("say $+$getnumber")){

Random random = new Random();
randomNumber = random.nextInt(100);
dos.writeUTF("产生了一个100以内的数");
}
...全文
260 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
brooksychen 2007-04-23
  • 打赏
  • 举报
回复
是啊,我也奇怪,或许是因为本来就是以这个结尾的字符串?
hugoon 2007-04-23
  • 打赏
  • 举报
回复
那为什么要用这个来写呢?有点奇怪
brooksychen 2007-04-23
  • 打赏
  • 举报
回复
String s = "test" + "say $+$getnumber";
System.out.println(s.endsWith("say $+$getnumber"));

以上代码输出为:true
这不就是说测试s是否以say $+$getnumber结尾吗?
hugoon 2007-04-23
  • 打赏
  • 举报
回复
一个猜字游戏:
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.*;

import javax.swing.JTextArea;

class ReadThread extends Thread{
JTextArea ta;
int randomNumber=-1;
DataInputStream dis;
DataOutputStream dos;

public ReadThread(JTextArea t,DataInputStream d,DataOutputStream dos){
this.ta = t;
this.dis =d;
this.dos = dos;
}

public void run(){
int i=0;
String s="";
try{
while(true){
s =dis.readUTF();

if (s.endsWith("say $+$getnumber")){

Random random = new Random();
randomNumber = random.nextInt(100);
dos.writeUTF("产生了一个100以内的数");
}
if (!s.endsWith("太大了")&&
!s.endsWith("太小了")&&
!s.endsWith("产生了一个100以内的数")&&
!s.endsWith("不是一个数字")&&
!s.endsWith("say $+$getnumber")){
System.out.println(s);
try{
int a = s.indexOf("say ");
String ss = s.substring(a+4,s.length());
i=Integer.parseInt(ss);
}
catch(NumberFormatException e){
dos.writeUTF("不是一个数字");
}

if (i!=randomNumber){
if(i>randomNumber){
dos.writeUTF(i+"太大了");
}else{
dos.writeUTF(i+"太小了");
}
}else{
dos.writeUTF(i+"对了");
}

}
ta.append("I say: "+s); //accept the msg
ta.append("\n");




}
}
catch(IOException e){
System.out.println("conncttiong error");
}
}
public int getRandomNumber(){
return randomNumber;
}

}
buyaowen 2007-04-23
  • 打赏
  • 举报
回复
$这个符号还真的不常见,也没听说用来做转义字符的
你从哪弄来的代码?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧