/**输出100——150不能被3整除的数,并且5个一行*/ public class TestBreak { public static void main(String[] args) { int count=0; for (int i=100;i<151;i++) { if (i % 3 == 0) { continue; } System.out.print(i+" "); count++; if (count==5){ System.out.println(); count=0; } } } }
老师,我对代码的位置有点搞得不太懂,我把int count=0;这句放在count++;这句上面,为什么输出的结果不一样呢
老师我这个Welcome输入W大写报错是什么情况
/*输出90-1里能被3整除的数*/ public class TestIfo3 { public static void main(String[] args) { for(int i=1;i<91;i++){ if (i/3==0){ System.out.println("i"); } } } }
老师,我这个问题出在哪呢?
byte b = 50; byte b = (byte)50;
老师,这两种写法有什么区别?
这个普通方法的修饰词为什么不是int String这种数据类型呢?Vehicle是属于什么类型啊,他返回一个空值这个值是返回给谁呢?返回这个值之后又有什么用呢?不太理解,像正常的a=3是把3赋值给a,这个是个方法,返回一个值这个值给了谁呢?
public class TestThis02 { int a = 1; int b = 2; String c; TestThis02(){ System.out.println(this); System.out.println(a+b); } TestThis02(int c ,int d ){ this(); a=c; b=d; System.out.println(this); System.out.println(a+b); } public static void main(String[] args) { TestThis02 hi = new TestThis02(); hi.a = 3; hi.b = 4; TestThis02 hi2 = new TestThis02(5,6); System.out.println(hi.a+hi.b); } }
运行结果如下图
在我的第二个含参构造器中我已经通过this引用了空的构造器,那这一步的作用是怎么体现的呢?引用无参构造器,打印出来的a+b=3,但是打印出来的this地址为什么是我第二个含参构造器的地址?然后我的含参构造器对a和b进行赋值,这个赋值是给了我的无参构造器构造出来的对象,还是给了我含参构造器构造出来的对象呢?如果是给我含参构造器的对象,那我这一步this()他的作用是什么呢?不是很理解,能不能出一个流程图看看他运行过程中的顺序和指向啊。老师讲的有点模糊,着实听不懂啊
老师,为什么有时候已经创建有参构造方法, 还要创建一个无参的构造方法呢
import java.awt.*; import javax.swing.*; public class BallGame extends JFrame { Image ball =Toolkit.getDefaultToolkit().getImage("images/ball(2).jpg"); Image desk =Toolkit.getDefaultToolkit().getImage("images/desk(1).jpg"); double x =200; double y =200; double degree = 3.14/3; //绘制窗口 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 (x>501-40-30||y<40+40){ degree = -degree; } //碰到左右边界 if (x>856-40-30||x<40){ degree = 3.14 - degree; } } //创建窗口 void launchFrame(){ setSize( 856,501); setLocation(100,100); setVisible(true); x = x+10; //实现动画,每秒绘制25次 while (true){ repaint(); try { Thread.sleep(40); } catch (InterruptedException e) { e.printStackTrace(); } } } public static void main(String[] args) { System.out.println("我的小游戏开始了!"); BallGame game = new BallGame(); game.launchFrame(); } }
代码是这样的,但是桌子的那个图片运行不出来
听了之后感觉很懵啊,是不是可以理解为类属于一个大的工厂,这个工厂中包含原材料,生产机器和机器的操作步骤,然后去生产出不同的产品,那这些材料,和机器是不是就相当于这个类的属性?机器的操作过程属于方法,那这个面向对象指的是谁呢?是生产出来的产品是对象吗?还是是说我的这些材料,生产机器以及生产方法就是对象。
老师,高琪老师上课用的绘制流程图的软件是啥啊
编译第二个类之后没有出现第二字节码是什么原因?
import java.util.Scanner; public class Test个税计算器 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("欢迎使用个税计算器"); System.out.println("输入66可重新计算"); System.out.println("输入88可退出程序"); while(true){ System.out.println("请输入您的当月薪资:"); int a =s.nextInt(); if(a==66){ System.out.println("重新计算\n"); continue; }else if(a==88){ System.out.println("退出程序。"); break; } System.out.println("请输入您的扣除项金额:"); int b = s.nextInt(); if(b==66){ System.out.println("重新计算\n"); continue; }else if(b==88){ System.out.println("退出程序。"); break; } int c = a-b-5000; int kouchue = 0; double shuilv=0; double d = 0; if(c<=3000){ shuilv = 0.03; kouchue = 0; d = c*shuilv-kouchue; }else if(c<=12000) { shuilv = 0.1; kouchue = 210; d = c * shuilv - kouchue; }else if(c<=25000){ shuilv = 0.2; kouchue = 1410; d = c * shuilv - kouchue; }else if(c<=35000){ shuilv = 0.25; kouchue = 2660; d = c * shuilv - kouchue; }else if(c<=55000){ shuilv = 0.30; kouchue = 4410; d = c * shuilv - kouchue; }else if(c<=80000){ shuilv = 0.35; kouchue = 7160; d = c * shuilv - kouchue; }else{ shuilv = 0.45; kouchue =15160; d = c * shuilv - kouchue; } System.out.println("应缴税额为:" + d); System.out.println("您的税后薪资为:" + (a - d)); System.out.println("请输入"); String e = s.nextLine(); if(e.equals("exit")){ break; } } } }
老师您好,这段代码最后的变量e在运行的时候为什么没有让我输入呢?直接跳回最初的循环了
运行是这样的
import java.awt.*; import javax.swing.*; public class BallGame extends JFrame { Image =Toolkit.().getImage(); Image =Toolkit.().getImage(); =; =; = /; paint(Graphics g){ System..println(); g.drawImage(,,,); g.drawImage(,() ,() ,); = +*Math.(); = +*Math.(); (>--||<+){ = -; } (>--||<){ = - ; } } launchFrame(){ setSize( ,); setLocation(,); setVisible(); = +; (){ repaint(); { Thread.(); } (InterruptedException e) { e.printStackTrace(); } } } main(String[] args) { System..println(); BallGame game = BallGame(); game.launchFrame(); } }
老师我这个桌子图片加载不出来,代码也没错呢
老师,我也碰见了和下面一样的情况。都出现最后一步到println这一步无法输出的现象,后发现在上课途中老师忘记讲解这个编译好的Java文件需要先保存,然后再在cmd窗口中进行调用才会有用。
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637