这个是什么问题呢
老师,这个课堂练习的代码中的sing()方法的作用是什么,是不是可以去掉啊。
老师:
outer:for() {
inner: for() {
continue outer;
}
老师,如果我在内存循环的每次循环时,出现了continue外层循环,那么这个是后是整个循环整体停止,还是说进入外层循环的下一次循环呢?
栈和堆里为什么都没有构造方法呢?
string底层是怎么实现的 啊老师,,,,,,
老师,为什么我这边溢出的时候返回的total不是负数?
package com.bjsxt.plane; import java.awt.*; /** * 炮弹类 */ public class Shell extends GameObject { double degree; //角度。炮弹沿着指定的角度飞行 public Shell() { x = 200; y = 200; degree = Math.random() * Math.PI * 2; //生成随机0~2π的角度 width = 5; height = 5; speed = 3; } @Override public void drawMyself(Graphics g) { Color c = g.getColor(); g.setColor(Color.yellow); g.fillOval((int) x, (int) y, width, height); g.setColor(c); //根据自己算法指定移动的路径 x += speed * Math.cos(degree); y += speed * Math.sin(degree); //碰到边界改变方向 if (y > Constant.GAME_HEIGHT - this.height || y < 40) { degree = -degree; } if (x < 0 || x > Constant.GAME_WIDTH - this.width) { degree = Math.PI - degree; } } }
g.setColor(Color.yellow);
这个Color.yellow为什么是这样调用,不能直接写yellow吗?
practice01.rar
老师,我按照视频敲完了但运行结果是窗口只被画了一次,图片也加载不出来是为什么呢
检查了很多次 还是报错 这个图片加载有问题
回来复习了一下
正常的
int a = 10000000000; //100亿 System.out.println(a); //整型超范围报错正常
为什么?
int money = 1000000000; //10亿 int years = 20; int total = money*years; //表达式money*years的值,超出了int范围为什么末没报错? System.out.println("total="+total); //溢出我明白
老师,您好,我在打印9×9乘法表时遇到了问题
下面两个代码和运行结果作为对比:
代码一:
/** * 练习打印9×9乘法表 * @author 陈其玉 * */ public class TestChengFaBiao { public static void main(String[]args) { for(int i=1;i<=9;i++) { for(int j=1;j<=i;j++) { System.out.print(j+"×"+i+"="+i*j+" "); } System.out.print("\n"); } } }
运行结果:
运行结束后,表格不能对齐。
代码二:
/** * 练习打印9×9乘法表 * @author 陈其玉 * */ public class TestChengFaBiao { public static void main(String[]args) { for(int i=1;i<=9;i++) { for(int j=1;j<=i;j++) { System.out.print(j+"×"+i+"="+i*j+"\t"); } System.out.print("\n"); } } }
此时表格是对齐的,我只是将空格换为了制表符
请问为什么使用制表符打出来后表格是对齐的???
我觉得制表符就是固定长度的空格,所以不理解。
package com.bjsxt; import java.awt.*; import javax.swing.*; public class BallGame extends JFrame{ Image ball = Toolkit.getDefaultToolkit().getImage("images/ball.png"); Image desk = Toolkit.getDefaultToolkit().getImage("images/desk.png"); double x = 200; double y = 200; double degree = 3.14/3; //这里的3.14是弧度,3.14弧度=180度 boolean right =true; //控制小球的水平位移方向 //绘制窗口 public void paint(Graphics g){ System.out.println("窗口被画了一次!"); g.drawImage(desk,0,0,null); g.drawImage(ball,(int)x,(int)y,null); x = x + 10*Math.cos(degree); y = y + 10*Math.sin(degree); //遇到上下边界 if (y<70 || y>501-40-30){ degree = - degree; } if (x>856-40-30||x<40){ degree = 3.14- degree; } } //创建窗口 void launchFrame(){ setSize(856,501); setLocation(100,100); setVisible(true); //每秒绘制窗口25次 while (true){ repaint(); try { Thread.sleep(40); //1s = 1000ms ,1秒25次等价于40毫秒一次 } catch (InterruptedException e) { e.printStackTrace(); } } } public static void main(String[] args){ System.out.println("我的小游戏开始了!"); BallGame ballGame = new BallGame(); ballGame.launchFrame(); } }
老师我这个能跑起来,但是它的上边界有点问题,用
if (y<70 || y>501-40-30)
才能达到预期效果,我用QQ截图截了一下运行效果,发现它把框体的高度也算进去了。这是为什么呀
s1s1s1 s2 s2namemajorheights2 s2s2height s2name s2major name height major
老师这样对吗
老师我用mac,影响学习之后的所有内容么
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637