这段c语言代码换成java是什么呢?求教啊

#include #include int main(){ char str[10000]; int i,len; while(gets(str)) { if(!strcmp(str,"#")) break; len = strlen(str); for(i = 0;i<len;i++) { if(str[i] == ' ') printf("%%20"); else if(str[i] == '!') printf("%%21"); else if(str[i] == '$') printf("%%24"); else if(str[i] == '%') printf("%%25"); else if(str[i] == '(') printf("%%28"); else if(str[i] == ')') printf("%%29"); else if(str[i] == '*') printf("%%2a"); else printf("%c",str[i]); } printf("\n"); } return 0;}

1个回答

package javaOJ;

import java.util.Scanner;

public class c {
public static void main(String[] args) {
String s;
//char[] s = new char[1000];
Scanner scanf = new Scanner(System.in);
while(true)
{
s = scanf.next();
char[] str = s.toCharArray();
// System.out.println(cs[0]);
if(str[0]=='#') break;
// System.out.println(cs.length);
int len=str.length;
for(int i=0;i<len;i++)
{
if(str[i]==' ')
System.out.print("%20");
else if(str[i]=='!')
System.out.print("%21");
else if(str[i]=='$')
System.out.print("%24");
else if(str[i]=='%')
System.out.print("%25");
else if(str[i]=='(')
System.out.print("%28");
else if(str[i]==')')
System.out.print("%29");
else if(str[i]=='*')
System.out.print("%2a");
else
System.out.print(str[i]);
}
System.out.println();
}
}
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!