java 常量池在哪里请问下面程序段哪里错了?

请问一下下面这个Java程序错在哪啊?_百度知道
请问一下下面这个Java程序错在哪啊?
ublic class Test4{ public static void main(String[] args){
byte x=129;
System.out.println(x)
提问者采纳
byte型的数据最大应该是到127
提问者评价
你是第一个回答的,当然要把分加给你。
错误代码: 没有任何的外部类型可访问
Undergraduate stud1=new Undergraduate();
Graduate stud2=new Graduate();
先生成外部类的对象,然后再new出内部类
StudentDome stud = new StudentDome();
Undergraduate stud1 = stud.new Undergraduate();
StudentDome stud0 = new StudentDome();
Graduate stud2=stud0.new Graduate();
其他类似问题
为您推荐:
其他4条回答
序没错.out,我估记你就是想测试溢出对吧?所以就不细说了,你把它赋给一个byte必须要强制转化才行。但是要记住,否则就会出错.println(x),但是要注意的是整数类型默认的都是指int类型; System。 程序像下面这样,比如你这里的128就是一个int类型:byte类型的范围是-128---127 超过这个范围就会溢出:public class Test4{ public static void main(String[] args){ byte x=(byte)129
public class Test4{ public static void main(String[] args){ byte x=(byte) 129; --129是int类型要强制转System.out.println(x); } }
楼上说的很清楚啦byte的取值范围是 -128~127你可以这样写public class Test4{ public static void main(String[] args){ byte num = 127;System.out.println(++num);System.out.println(++num);} }
byte最大值是127
byte x = 129
会提示无法把整型转换成byte型
您可能关注的推广
java程序的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁下面一行简单的java代码报错,请问为什么 ?
public class Mytest {
int a = 1;
按投票排序
The Java Language Specification, Third Edition [1] 第 8.1.6 节 [2]:
-A class body may contain declarations of members of the class, that is, fields (§8.3)-
第 8.3 节 [3]:
-The variables of a class type are introduced by field declarations:
FieldDeclaration:
FieldModifiers(opt) Type VariableD
VariableDeclarators:
VariableDeclarator
VariableDeclarators , VariableDeclarator
VariableDeclarator:
VariableDeclaratorId
VariableDeclaratorId = VariableInitializer
VariableDeclaratorId:
Identifier
VariableDeclaratorId [ ]
VariableInitializer:
Expression
ArrayInitializer-
以上规定的意思就是——仅仅针对你提供的例子而言——在声明类成员(field)的时候,要写成
类型 变量声明 ;
的形式。其中变量声明(VariableDeclarator)又可以写成
变量名 = 变量初始化表达式
的形式。这里最重要的是,定义一个成员变量的时候,必须写出它的类型,所以按照你的写法,编译器出错的原因,就是因为这种写法不符合语法上的规定。
合乎规定的写法比如(不完全列表):
public int alpha = 1;
public int a, b, c = 2;
public int d = 2, e = 3;
int g[] = {1, 2, 3};
String h = randomString();
此外,如果你把例子改成
public class Mytest { int a = 1; int a = 2; }
也就是重新定义一次 a ,结果仍旧会报错,虽然这样写合乎上面说的语法,但仍旧是一个错误,因为第 8.3 节里又规定说:
-It is a compile-time error for the body of a class declaration to declare two fields with the same name.-
综上所述,报错的原因就是……设计 Java 语言的人规定你不可以这么写。
(顺便抱怨一下,知乎的编辑器实在 反 人 类。)
变量的赋值(a = 2)必须在方法体内或代码块中,如:
int a = 1;
连续定义多个变量时, 用逗号分开, 不是分号....好多语言都这样, C, C++...
int a = 1, b = 2;> 问一下,我这么简单的语句哪里错啦,迷糊了importjava.util.Aimport
问一下,我这么简单的语句哪里错啦,迷糊了importjava.util.Aimport
javachxy & &
发布时间: & &
浏览:173 & &
回复:1 & &
悬赏:0.0希赛币
问一下,我这么简单的语句哪里错啦,迷糊了import & java.util.A
public & class & more & {
& * & @param & args
public & static & void & main(String[] & args) & {
// & TODO & Auto-generated & method & stub
int[] & s=new & int[]{3,6,0,1,6,2,33};
Arrays.sort(s,new & Lower());
for(int & i=0;i &s.i++){
System.out.println(s[i]);
class & Lower & implements & Comparator &Integer& {
public & int & compare(Integer & s1,Integer & s2){
return & s1& s2 1:(s1==s2 0:-1);
如果你给sort传入一个(s,new Comparator &Integer& )对象,则s必须是Integer数组,而你的s是一个int数组类型.javaee2008 & &
& & (0)(0)
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&&&湘教QS2-164&&增值电信业务经营许可证湘B2-java编程所有质数(素数)交换到一组前面,请问一下错哪里?_百度知道
java编程所有质数(素数)交换到一组前面,请问一下错哪里?
}输出结果是00000.println(num1[a]+&d&);
num[c]=num[e]。我写的代码如下;5,b;a++) {
for(c=0;1;=
if(num[c]%d==0)
num[c]=num1[b]?我不懂,d,e=0,非质数交换在后面;请输入数字;
num[a]=input.out,f,怎么回事.
for(a=0:编写一个Java程序.length-1;a&a++) {
System.nextInt().length-1;
break.println(&quot.in); &quot,c;
int a,b=num:int num[]=new int[5];c++)
for(d=num[c]-1;
for(a=0:&c&a& int num1[]=new int[5];
Scanner input=new Scanner(System,e题目要求,并输出处理后的结果,将这个数列中所有质数(素数)交换到前面
提问者采纳
你全程都没给 num1数组赋值当然最后是初始值了0,注释下代码,可以理清思路
其他类似问题
&&&&&if&S13&&&&&&&&&&&&&&&0;}&nbsp,&&&&&&&&&a[i];j++)&&&&&(j&&&&&main(String[]&&&{&&2)&&==&&&&&(int&&&{//&&&int[a,&&&&=&&&n++;&&&&&&nbsp.&else&(int&&;&&&&nbsp,&&=&&&&&&&&&nbsp,m是b数组索引最大值;&&//&int&&&&&&&&如果能被整出就不是质数;&&a[]&&for&&&&i&&{&&&nbsp.println(A&&&&&&&&&j&i&&&&&&&&&nbsp!=&&&{&&&=&&&0)&&&nbsp,&&&//&nbsp,直接保存到数组b的前端&&&&&nbsp.length);&&&&(a[i]&}&nbsp.length];&&&&&&if&A&&&&a&&&&&&&&&&&&&如果不能被整出就继续循环&b;&&&&&=&&-&&b[]&&&&&{//&打印数组&&nbsp,&nbsp,&&{&&&&&4;b[m]&&&nbsp,&&如果是1或者是2的话直接保存到数组b的后端&&&&n&8;&3;&0;&void&for&&&&&&&&(a[i]&&&&&&&&m--;&6;&&1,&&&nbsp,&&&nbsp.copyOfRange(b;&&{//&&&&//&&nbsp,&&&&&nbsp,n是b数组索引的最小值&m--;&&==&&m&&&if&}&&9;&&&&&&&&&可以用Scanner获取(此处写死方便测试)&&2;&&&&&nbsp,&&b.toString(a));&&&&}&&}&=&&&new&};&&&a[i];&&&&&&&&&&&a[i]&&&}&&&&2;&7;a[i]&=&&&{&&&&&b[m]&j&&&&&&&&&&&&&&&&&||&&&&-&&//&=&&&&&&&&&1;&&&&&&&&i是循环次数;&&&&&&&&&&nbsp这个代码估计会好点public&&==&&i++)&&&&5;a[i];&&将b数组拷贝回a数组&&&int&&&0;&&&&&=&&args)&&1)&=&&&&&&&&nbsp,&&a;1&=&&b[n]&nbsp,&&&j&&break.&&&&&&&%&&a[i].length&static&nbsp
来自团队:
为您推荐:
素数的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁请问下面这段代码错在哪里啊?
[问题点数:20分,结帖人binglingxueyou]
请问下面这段代码错在哪里啊?
[问题点数:20分,结帖人binglingxueyou]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。}

我要回帖

更多关于 java 常量池在哪里 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信