Java返回不可能的随机数
代码如下:Java返回不可能的随机数,java,Java,代码如下: import java.lang.*; import java.io.*; class string { public static void main(String[] args) { try { boolean go = true; BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
import java.lang.*;
import java.io.*;
class string
{
public static void main(String[] args)
{
try
{
boolean go = true;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer inp = new StringBuffer(br.readLine());
System.out.println(inp.reverse());
inp.reverse();
int leng = inp.length();
inp.setLength(leng+100);
int x = 0;
StringBuffer res = inp;
William bill = new William();
res=bill.will(x+1, leng, res);
while(x<leng-1 && go)
{
if(inp.charAt(x)==' ' && go)
{
res=bill.will(x+1, leng, res);
go = bill.bob();
}
x=x+1;
}
System.out.println(res);
}
catch (IOException uhoh)
{
System.out.println("You entered something wrong.");
System.exit(1);
}
}
}
class William
{
public boolean go;
public William()
{
this.go=true;
}
public StringBuffer will(int start, int len, StringBuffer input)
{
char cur = input.charAt(start-1);
input.delete(start-1, start-1);
int x = start;
boolean happy=true;
while(x<len && happy)
{
if(x==len-2)
{
this.go=false;
input.insert(cur, x+1);
x=x+2;
happy=false;
}
else if(input.charAt(x)==' ')
{
input.insert(cur, x);
x=x+1;
happy=false;
}
else
{
x=x+1;
}
}
return input;
}
public boolean bob()
{
return this.go;
}
}
import java.lang.*;
导入java.io.*;
类字符串
{
公共静态void main(字符串[]args)
{
尝试
{
布尔go=true;
BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in));
StringBuffer inp=新的StringBuffer(br.readLine());
System.out.println(inp.reverse());
inp.reverse();
int leng=inp.length();
输入设定长度(长度+100);
int x=0;
stringbufferres=inp;
威廉·比尔=新威廉();
res=比尔·威尔(x+1,长度,res);
而(x您有StringBuffer.insert()的参数向后。它是(偏移量,字符)
您有StringBuffer.insert()的参数向后。它是(偏移量,字符)
试试看
input.insert(x+1,cur);
代替input.insert(cur,x+1);
(与输入相同。插入(cur,x)
)尝试
input.insert(x+1,cur);
代替input.insert(cur,x+1);
(和
输入相同。插入(cur,x)
)我想Lou已经得到了你的答案,但是对于未来的问题,有意外的结果,既有测试输入又有测试输出是非常酷的。我想Lou已经得到了你的答案,但是对于未来的问题,有意外的结果,既有测试输入又有测试输出是非常酷的。