经典屏保

标题:典屏保 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
DVD机在视频输出时,为了保护电视显像管,在待机状态会显示“屏保动画”,如下图所示,DVD Logo在屏幕内来回运动,碰到边缘会反弹:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
        String[] s = scan.nextLine().split(" ");
        scan.close();

        int width = 800, height = 600, w = 50, h = 25, _x = 1, _y = 1, x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]), t = Integer.parseInt(s[2]);

        for (int i = 0; i < t; i++) {
            if (x == 0) {
                _x = 1;
            }
            if (x + w == width) {
                _x = -1;
            }
            if (y == 0) {
                _y = 1;
            }
            if (y + h == height) {
                _y = -1;
            }

            x += _x;
            y += _y;
        }
        System.out.println(x + " " + y);
    }
}




全部评论

相关推荐

05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务