用类来替代public class str
{
    public int a = 0;
    public char b = '';
    public int c = 0;
}

解决方案 »

  1.   

    ^_^
    调用时呢?
    是像这样吗?
    str.a=111;
    str.b='b';
      

  2.   

    需要新建对象str aStr = new str();str.a = 111;
    str.b = 'b';
      

  3.   

    搞错,对不起:str aStr = new str();aStr.a = 111;
    aStr.b = 'b';
      

  4.   

    public class Test
    {
    private static class Struct
    {
    int i;
    String s;
    }

    public static void main( String[] args )
    {
    Struct st = new Struct( );
    System.out.println( st.i +"\t" + st.s );
    st.i = 90;
    st.s = "a string";
    System.out.println( st.i + "\t" + st.s );
    }
    }
      

  5.   

    基本上这个想怎么写就怎么写,写个类嘛,没什么格式限制的。C++里面也提倡用类代替struct
      

  6.   

    成功了,谢谢小P和AGEN我的测试代码是:
    <%@page contentType="text/html;charset=8859_1" %>
    <html>
    <head>
    <title>测试结构体变量</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF" text="#000000">
    <% class Struct
    {
    int i;
    String s;
    }

    Struct st = new Struct( );
    out.print( st.i +"|||||" + st.s +"<br>");
    st.i = 90;
    st.s = "a string";
    out.print( st.i + "|||||" + st.s );
    %>
    </body>
    </html>
    写下来给后面的人作参考吧   ^_^
      

  7.   

    呀呀呀 .
    多嘴问一句
    要将这个结构体变量声明成数组,是这样的吗? 报错啊
    ..............\teststruc_jsp.java:57: ']' expected
    Struct st [2] = new Struct( );
                                ^
    <%
    class Struct
    {
    int i;
    String s;
    }

    Struct st [2] = new Struct( );
    out.print( st[0].i +"||||" + st[0].s  +"<br>");
    st[0].i  = 90;
    st[0].s  = "a string";
    out.print( st[0].i  + "||||" + st[0].s  );%>
      

  8.   

    Struct st[2] = new Struct[2];