为什么显示错误:Undefine name 's'

forprograme 2002-04-04 07:40:21
import java.io.*;
public class Runtime1
{
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static void main (String[] args)
{
int i=0;
try{
String s[]=new String[2];
s[0]="/windows/exit.com";
s[1]="test.txt";
Runtime R=Runtime.getRuntime();
Process p=R.exec(s);
InputStream in=p.getInputStream();
OutputStream out=p.getOutputStream();
InputStream err=p.getErrorStream();
int exitcode=0;
try{
exitcode=p.waitFor();
}
catch (InterruptedException e){
}
System.out.println("Please print!!!!!!");
\\语句1:
System.out.println(s[0]+"exited withcode"+exitcode);
}catch(java.io.IOException e){}
System.out.println(s[0]+s[1]);
while(i++<10000);
}
}
为什么语句1没有输出?
为什么显示错误:Undefine name 's'?
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
forprograme 2002-04-06
  • 打赏
  • 举报
回复
可是语句1没输出为什么?
forprograme 2002-04-06
  • 打赏
  • 举报
回复
明白,谢谢,
jiyunang 2002-04-04
  • 打赏
  • 举报
回复
public static void main (String[] args)
{
int i=0;
try{
String s[]=new String[2];
s[0]="/windows/exit.com";
s[1]="test.txt"
Runtime R=Runtime.getRuntime();
Process p=R.exec(s);
InputStream in=p.getInputStream();
OutputStream out=p.getOutputStream();
InputStream err=p.getErrorStream();
int exitcode=0;
try{
exitcode=p.waitFor();
}catch (InterruptedException e){
}
System.out.println("Please print!!!!!!");
\\语句1:
System.out.println(s[0]+"exited withcode"+exitcode);
}catch(java.io.IOException e){}
System.out.println(s[0]+s[1]);//<--Undefine name 's'
while(i++<10000);
}
看清楚了吧
你s定义在try的模块中
zfluo 2002-04-04
  • 打赏
  • 举报
回复
String[] s = new String[2];

62,614

社区成员

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

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