dyxm21
dyxm21
2016-05-18 11:36
采纳率: 80.3%
浏览 1.2k
已采纳

这段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条回答 默认 最新

  • weichongyu
    魏春雨 2016-05-18 12:32
    已采纳

    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();
    }
    }
    }

    点赞 评论

相关推荐