小编Amb*_*er 的帖子

根据相应的数字缩短打印月份名称的程序

该程序要求用户输入等于或等于1-12的任何数字.然后它将数字转换为将要打印的消息(复制程序以自己查看).有没有办法缩短代码?

import javax.swing.JOptionPane;

public class NumOfMonth {

public static void main(String[] args) {



    int num = Integer.parseInt (JOptionPane.showInputDialog ("Enter any number equal to or between 1-12 to display the month"));

    switch (num)
    {
    case 1:
        System.out.println ("The name of month number 1 is January");
        break;
    case 2:
        System.out.println ("The name of month number 2 is February");
        break;
    case 3:
        System.out.println ("The name of month number 3 is March");
        break;
    case 4:
        System.out.println ("The name of month number 4 is April"); …
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
1
解决办法
1692
查看次数

计算单词中的字符和子字符串

当输入"last"一词时,我必须阅读未知数量的单词并终止程序.我必须:

  • 显示以"S"开头的名称数.
  • 显示以"d"结尾的名称数量.
  • 显示以"anne"结尾的名称数.

问题:我遇到的唯一问题是显示以"anne"结尾的名称数量.它显示0,除非我只输入单词"anne",否则它显示1.

注意:

  • 我们还没有开始使用数组.
  • 这是我在编写测试之前正在练习的工作,这不是应该交给我的作业.

我的代码:

unit Ess_U;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    redOut: TRichEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var wrd : string;
    Scount, dcount, Namecount : integer;
begin
redOut.clear;
   Scount := 0;
   dcount := 0;
   Namecount := 0;


   repeat
    wrd := inputbox ('Input …
Run Code Online (Sandbox Code Playgroud)

delphi

3
推荐指数
1
解决办法
170
查看次数

为什么我的输入框不按顺序显示?

我需要制作一个程序,输入并显示产品的信息(品牌名称,内容,质量和库存量).

问题:即使编写代码以按顺序显示代码,此代码中的输入框也不会按顺序完全显示.输入框按此顺序排列:"内容","质量","库存","品牌名称",实际上应该是"品牌名称","内容","质量","库存".(这些是输入框的标题).

- 我认为这可能是源代码(向下滚动程序的其余部分):

 StrObj := TProducts.Create(Inputbox('Brand name', 'Input the brand name', ''),Inputbox('Contents', 'Input the contents', ''), StrToInt(Inputbox('Mass', 'Input the mass', '')), StrToInt(Inputbox('Stock', 'Input the number in stock', '')));
Run Code Online (Sandbox Code Playgroud)

注意:

- 所有数据都会转到预定的位置,因此输入框的顺序根本不会影响程序.我想知道是否有办法使输入框按顺序显示.

- 这是一项作业,但输入框的顺序不会计算标记.

整码:

应用:

unit TProducts_U;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, TProducts_class;

type
  TForm1 = class(TForm)
    btnResult: TButton;
    redOut: TRichEdit;
    procedure btnResultClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm} …
Run Code Online (Sandbox Code Playgroud)

delphi

1
推荐指数
1
解决办法
97
查看次数

标签 统计

delphi ×2

java ×1