RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
alex_t
Asked: 2025-02-21 01:07:15 +0000 UTC

Java 中的顺序函数调用

  • 5

我通过阅读 C/C++ 教科书开始接触编程。在“功能”主题中有这样的信息:

“每个函数都有自己的名字,当在程序中遇到它时,控制权就传递给该函数的主体。这个过程称为函数调用(或函数调用)。当函数返回时,程序执行从函数调用后的行恢复”:

在此处输入图片描述

我一直没有读完那本教科书,而是转而使用 Java 语言,并一直用它来学习和写作。现在我认为我对 Java 中所有未知的东西的看法是:“好吧,它可能与 C++ 类似。”我是否正确理解了 Java 中的顺序方法调用与 C++ 中的顺序方法调用类似?我刚画了这张图:

在此处输入图片描述

我尝试用Java编写此代码:

public class Demo1 {

    public static void main(String[] args) throws InterruptedException {
        System.out.println("START main()");
        funcOne();
        funcTwo();
        System.out.println("FINISH main()");
    }

    private static void funcOne() throws InterruptedException {
        System.out.println("  Start funcOne()");
        f_1_1();
        f_1_2();
        f_1_3();
        System.out.println("  Finish funcOne()");
    }

    private static void funcTwo() throws InterruptedException {
        System.out.println("  Start funcTwo()");
        f_2_1();
        f_2_2();
        System.out.println("  Finish funcTwo()");
    }

    private static void f_1_1() throws InterruptedException {
        System.out.println("    start f_1_1()");
        Thread.sleep(1_000L);
        System.out.println("    finish f_1_1()");
    }

    private static void f_1_2() throws InterruptedException {
        System.out.println("    start f_1_2()");
        Thread.sleep(2_000L);
        System.out.println("    finish f_1_2()");
    }

    private static void f_1_3() throws InterruptedException {
        System.out.println("    start f_1_3()");
        Thread.sleep(3_000L);
        System.out.println("    finish f_1_3()");
    }

    private static void f_2_1() throws InterruptedException {
        System.out.println("    start f_2_1()");
        Thread.sleep(4_000L);
        System.out.println("    finish f_2_1()");
    }

    private static void f_2_2() throws InterruptedException {
        System.out.println("    start f_2_2()");
        Thread.sleep(5_000L);
        System.out.println("    finish f_2_2()");
    }
}

我在控制台中得到输出:

在此处输入图片描述

嗯,从各方面来看,Java 中方法的调用方式确实与 C++ 类似。奇怪的是,Java 教科书中没有任何地方明确写到这一点(或者也许我读错了教科书)。

java
  • 1 个回答
  • 87 Views
Martin Hope
H_u_n_t_3_r
Asked: 2025-02-20 22:39:44 +0000 UTC

如何使Jframe中Jpanel上的符号颜色平滑变化?

  • 5

因此,我有一个代码,可以绘制像电影中那样的矩阵,并且我指出了数字以高百分比掉落的可能性。我的问题是,我希望所有的符号都不是静态的,而是闪烁的。也就是说,当符号达到绿色的上限(255)时,它开始变暗(最多 50)。我还希望它在大约10秒内发生(单程)。

import javax.swing.*;
import java.awt.*;
import java.util.Random;

import static java.awt.FlowLayout.CENTER;
import static java.lang.Math.floorDiv;

public class BigProject extends JFrame {
    public static void main(String[] args) {

        var random = new Random();

        var f = new JFrame();
        f.getContentPane().setBackground(Color.BLACK);
        f.setDefaultCloseOperation(EXIT_ON_CLOSE);
        f.setUndecorated(true);
        f.getContentPane().setLayout(new FlowLayout(CENTER, 0, 0));

        var screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        var labelSize = new Dimension(100, 60);
        var rw = screenSize.getWidth() / (int) labelSize.getWidth();
        var rh = screenSize.getHeight() / (int) labelSize.getHeight();
        var repeat = rw * rh;

        var digit = new String[]{
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
        };
        var letter = new String[]{
                "a", "b", "c", "d", "f", "g", "h", "i", "j", "k",
                "l", "m", "n", "o", "q", "r", "s", "t", "u", "y",
                "x", "z"
        };

        for (var i = 0; i < repeat; i++) {
            int a = random.nextInt(25);
            if (a < 5) {
                var number = random.nextInt(letter.length);
                var label = getLabelG(labelSize, random, letter[number]);
                f.add(label);
            }
            if (a >= 5) {
                var number = random.nextInt(digit.length);
                var label = getLabelG(labelSize, random, digit[number]);
                f.add(label);
            }
            f.setExtendedState(Frame.MAXIMIZED_BOTH);
        }
        f.setVisible(true);


    }
    private static JLabel getLabelG(Dimension labelSize, Random random, String letter) {
        var label = new JLabel(letter, SwingConstants.CENTER);
        label.setPreferredSize(labelSize);
        label.setFont(label.getFont().deriveFont(48.0F));
        label.setForeground(new Color(0, 50 + random.nextInt(206), 0));
        return label;
    }
}
java
  • 1 个回答
  • 35 Views
Martin Hope
user658408
Asked: 2025-02-20 22:33:58 +0000 UTC

适配时如何适当缩减日历?

  • 4

我达到了需要缩小日历的分辨率,它的垂直边已经靠近屏幕边框。似乎我减小了宽度,但屏幕仍然“浮动”,我想是因为 fc-daygrid-body fc-daygrid-body-unbalanced div 之前的所有内容都没有减小尺寸并且超出了屏幕边界。我可能错了,但检查员就是这么想的。我不知道该如何解决这个问题,所以我在这里写下来。在文档中我只找到了一个付费插件。也许我遗漏了什么?如果您能指出解决这一困境的方法,我将不胜感激。

document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
     headerToolbar: false,
    dayHeaders: false,
    dayCellContent: function(e) {
      
      if(e.date.getDate() < 10){
        return {
          html: `<span class="date">0${e.date.getDate()}</span>|<span class="month">${e.date.toLocaleDateString('ru-RU', {month: 'short'})}</span>`
          
        }
      }
      else{
        return {
          html: `<span class="date">${e.date.getDate()}</span>|<span class="month">${e.date.toLocaleDateString('ru-RU', {month: 'short'})}</span>`
          
        }
      }
        
        
      
      
      
    },
    
    eventClassNames: 'event-class',
    eventContent: function(arg) {
      
      return {
        html: '<div><img src="https://placehold.co/50x70"/></div>'
        
      }
      
    },
    events: [{
        title: 'event 1',
        date: '2025-02-04'
      },
      {
        title: 'event 2',
        date: '2025-02-17'
      }
    ]
  });
  // console.log(document.querySelector('.date'))
    
    calendar.render();
     
  });
  
   

/*style.css*/
  
body{
   background-color: #131313; 
}
.title__game__release__calendar{
    display: flex;
    justify-content: center;
    padding: 100px 0 52px 0;
}
.title__game__release__calendar h2{
    color: #EB5284;
    font-size: 115px;
    text-transform: uppercase;
}

.game__release__calendar #calendar{
    width: 812px;
   margin: 0 auto;
   padding: 0 0 100px 0;
   
}


.game__release__calendar #calendar a{
color: #ffffff;
}
 .game__release__calendar #calendar.fc td, .fc th {
    border-style: none;
  } 
  .game__release__calendar #calendar .fc-scrollgrid.fc-scrollgrid-liquid{
    border: none;
   }
   .fc-daygrid-day-frame.fc-scrollgrid-sync-inner {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    border: solid 1px #EB5284;;
  }
  
  
  .event-class {
    margin: 0 !important;
    font-size: 0;
    border: none;
  }
  
  .cell-class {
    background: black;
    color: rgb(188, 179, 207);
    --fc-border-color: #2d2d2d;
  @media(max-width:819px){
 #calendar table.fc-scrollgrid-sync-table{
    width: 690px !important; 
    margin: 0 auto;
}
  }
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles/style.css">
    <title>Document</title>
</head>
<body>

<section class="game__release__calendar">
            <div class="container">
                <div class="title__game__release__calendar">
                    <h2>Календарь релизов</h2>
                </div>
                <div id='calendar'></div>
            </div>
        </section>
   <script src='https://cdn.jsdelivr.net/npm/[email protected]/index.global.min.js'></script>
    <script src="scripts/calendar.js"></script>
</body>

</html>

p.s. 还有一个带有 bootstrap 的自适应版本,但我没有检查。更新:图书馆链接https://fullcalendar.io/

javascript
  • 1 个回答
  • 48 Views
Martin Hope
M.F
Asked: 2025-02-20 18:03:25 +0000 UTC

为什么命令行中的输出不正确?

  • 3

情况如下:在 Windows 10 命令行中

输入命令时:

>>> for i in [1, 2, 3]:
...     print(i, end = ' ')

输出:3

而不是:1 2 3

在 IDLE(Python)和 PyCharm 中一切都显示正确。

据我了解, end() 不仅替换 \n ,还替换 3 之前的所有内容。该问题仅出现在 Windows(10)命令行中的交互式 Python 会话中。

这是命令行: 命令行

这是空闲状态: 在此处输入图片描述

这是 PyCharm:在此处输入图片描述

python
  • 2 个回答
  • 54 Views
Martin Hope
Polundra
Asked: 2025-02-20 16:08:11 +0000 UTC

正确遍历图。可以优化吗?

  • 5

该图以邻接字典的形式给出。需要遍历图的顶点(在本例中为迭代 DFS)

def iteractive_dfs(graph, start, path=None):
    if path is None:
        path = []
    q = [start]
    while q:
        v = q.pop()
        print(v)
        if v not in path:   # new point
            path = path + [v]
# need add to stack visited point first
#            l1 = list(graph[v])
#            for point in l1:
#                    if point in path:
#                        q.append(point)
#                        l1.remove(point)
#                        break

#            q += l1
            q +=graph[v]   

    return path

graph = {0: [6, 8, 3, 5], 1: [2, 7], 2: [1, 5], 3: [0, 4], 4: [3], 5: [0, 2], 6: [0], 7: [1], 8: [0]}
iteractive_dfs(graph, 0) # начинаем обход с вершины 0

在我们的例子中,我们得到以下轨迹:0 - 5 - 2 - 5 - 1 - 7 - 1 - 2 - 0 - 3 - 4。但是,从逻辑上讲,正确的轨迹应该是:0 - 5 - 2 - 1 - 7 - 1 - 2 - 5 - 0 - 3 - 4。也就是说,从字典中添加时,堆栈顶部应该有未访问的顶点。这可以通过使用注释的代码片段并删除来实现。 q +=graph[v] 但有人担心,对于大型图来说,这种设计在执行时间方面并不是最优的。可以优化吗?谢谢。

python
  • 2 个回答
  • 75 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5