小问题 用类来替代public class str{ public int a = 0; public char b = ''; public int c = 0;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ^_^调用时呢?是像这样吗?str.a=111;str.b='b'; 需要新建对象str aStr = new str();str.a = 111;str.b = 'b'; 搞错,对不起:str aStr = new str();aStr.a = 111;aStr.b = 'b'; 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 ); }} 基本上这个想怎么写就怎么写,写个类嘛,没什么格式限制的。C++里面也提倡用类代替struct 成功了,谢谢小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>写下来给后面的人作参考吧 ^_^ 呀呀呀 .多嘴问一句要将这个结构体变量声明成数组,是这样的吗? 报错啊..............\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 );%> Struct st[2] = new Struct[2]; tomcat服务启动,应用程序无法访问的异常,请各位高手帮忙解决。 求救:在java代码里拼html代码 u盘中毒杀不了 请高手翻译代码?我不懂java只懂.net 给翻译出来最好 一小问题!但很长!代码也违反了MVC 但.. 简单问题...在线等老鸟~ 对多字段的表的操作问题 怎样把字符串转成日期型 什么地方有J2SE,J2EE的CHM格式的文档 紧急求救:怎样在jsp中实现文件的上传和下载. 请问有关汉字编码问题,非常感谢好心人!! ResultSet对象的first()方法还有absolute()都不能用,是什么问题
调用时呢?
是像这样吗?
str.a=111;
str.b='b';
str.b = 'b';
aStr.b = 'b';
{
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 );
}
}
<%@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>
写下来给后面的人作参考吧 ^_^
多嘴问一句
要将这个结构体变量声明成数组,是这样的吗? 报错啊
..............\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 );%>