小编Gru*_*ear的帖子

具有不同数据类型的数组,即字符串和整数.(Objectorientend)

比如我

3本书: Booknumber (int), Booktitle (string), Booklanguage (string), Bookprice (int).

现在我想要一个名为的数组books[3][4].

我是通过setBooknumber设置的数据,如下所示:
Book1.getBooknumber(), Book1.getBooktitle(),...,Book3.getBookprice().

现在我怎么意识到这一点books[3][4] array.我不能称之为String books[][] = new String [3][4].因为我无法Booknumber (int)进入它.

我不希望Booknumber成为String也不是Bookprice.请问我怎么意识到这一点?

现在进一步阐述它.

我有2节课.

public class book{
String Booktitle, Booklanguage;
int Booknumber, Bookprice;

//constructor

//get

//set
}
Run Code Online (Sandbox Code Playgroud)

public class bookUI
{
 public static void main(String arg[])
 {
   book book1 = new book();
   book book2 = new book();
   book book3 = new book();

   book1.setBooktitle();
   ...
   book3.setBookprice();

   //Here I want to have …
Run Code Online (Sandbox Code Playgroud)

java arrays types object

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

一种更有效的动词算术/字母表方法?

也许大多数人都知道Send + More = Money.好吧,我现在正在学习java,其中一个练习是我要解决HES + THE = BEST.

现在,到目前为止,我可以/应该使用if-for-while-do循环,没有别的.虽然我确定有不同的方法来解决它,但这不是我正在经历的练习的重点.我必须能够以最有效的方式使用if-for-while-do循环.

我的问题?我似乎无法想出解决它的有效方法!我想出了这个,它解决了这个难题,但也许是最有效的方法:

public class Verbalarithmetics {

    public static void main (String args[]) {
        // Countint Variables
        int index_h = 0;
        int index_e = 0;
        int index_s = 0;
        int index_t = 0;
        int index_b = 0;

        // Start with h = 1 and increase until the else-if statement is true
        for(int h = 1; h <= 9; h++) { // h = 1, because first Symbol can't be zero
            index_h++;
                // …
Run Code Online (Sandbox Code Playgroud)

java math performance cryptarithmetic-puzzle alphametic-question

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

Node.js&npm:如何创建自定义npm cli命令?

比方说,我经常使用npm list -g -depth 0命令,我想用npm listC或者别名npm list -c1.

我怎么做?

node.js npm

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

Java GUI编程:设置Fore/Background

我刚刚进入GUI编程,慢慢学习.

但是我遇到了蝙蝠的问题.我根本无法在窗口中更改Fore/Background颜色.

但是,当我通过JLabel添加标签然后使用setFore/Back时,它们会很好地改变颜色.只是没有整个窗口.

我以为.setForeground和.setBackground应该改变窗口的颜色?

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

public class MyWindow {

    public static void main(String args[])
    {
         Runnable init = new Runnable()
         {
             public void run()
             {

                    JFrame myWindow = new JFrame("Hola!");
                    myWindow.setForeground(Color.YELLOW);
                    myWindow.setBackground(Color.YELLOW);
                    myWindow.setSize(400, 300);

                    myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    myWindow.setLayout(null);

                    myWindow.setVisible(true);

             }

         };
         SwingUtilities.invokeLater(init);
    }


}
Run Code Online (Sandbox Code Playgroud)

java user-interface swing colors jframe

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

如何询问对象是否属于类x?

所以我有Shape.h,Rectangle.h,Circle.h和main.cpp.

Shape.h得到:

class Shape{
public:
    Shape() {};
    ~Shape() { cout << "Destroy Shape."; };

    virtual double getArea() = 0;
    virtual double getCircumference() = 0;
};
Run Code Online (Sandbox Code Playgroud)

矩形和圆形各自的代码.

现在在main.cpp我做

Shape* newRectangle= new Rectangle(4, 8);
Shape* newCircle= new Circle(10);
Run Code Online (Sandbox Code Playgroud)

到目前为止,所有罚款和花花公子.这是我难倒的地方.我知道我要做什么,我只是不知道怎么做.

我正在尝试编写一个函数来检查Shape*对象是否属于Circle.

它就是这样的

if Shape* object belongs to Object-Type Circle, then
cout << "It's a Circle, bruh!";
else
cout << "Ain't a circle, yo!";
Run Code Online (Sandbox Code Playgroud)

谷歌搜索后我开始:

void check(Shape & object){
    Circle& checkObject = dynamic_cast<Circle&>(object);

}
Run Code Online (Sandbox Code Playgroud)

main中的函数将通过以下方式调用:

check(*newRectangle);
check(*newCircle);
Run Code Online (Sandbox Code Playgroud)

但我还没有得到如何继续的线索:(.任何帮助和解释都表示赞赏.谢谢!

c++ object

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

将键入的文本转换为小写

我有一个index.jsp

[剪断]

<% 
  String name = request.getParameter("name");
  String pass = request.getParameter("pass");
  String globalname = "webeng";
  String globalpass = "2009";
  if (name !=null && pass!=null && name.equals(globalname) && pass.equals(globalpass))
   {
   %>
    <hr />
    <p><b>Howdy, <%= request.getParameter("name") %></b></p>
    <hr />
<% }
  else if (name !=null | pass!=null && name.equals("") | pass.equals(""))
  {
  %>
    <hr />
    <p><b>Ooops, one or more fields are empty. Please fill everything out!!</b></p>
    <hr />
<% }
  else if (name !=null | pass!=null && !name.equals(globalname) | !pass.equals(globalpass))
  { …
Run Code Online (Sandbox Code Playgroud)

java string jsp lowercase

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