我们现在正在学习如何使用多个类Java,并且有一个项目要求创建一个Circle包含a radius和a的类diameter,然后从主类中引用它来查找直径.此代码继续收到错误(在标题中提到)
public class Circle
{
public CircleR(double r)
{
radius = r;
}
public diameter()
{
double d = radius * 2;
return d;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助,-AJ
更新1:好的,但我不应该将第三行声明public CircleR(double r)为双,对吧?在我正在学习的书中,这个例子没有那样做.
public class Circle
{
//This part is called the constructor and lets us specify the radius of a
//particular circle.
public Circle(double r)
{
radius = r;
}
//This is a method. It performs some action (in this case …Run Code Online (Sandbox Code Playgroud) 我只是学习Swing,并为自己构建了一个示例GUI作为练习.非常基本的,它在西侧,中间和东侧有三个面板JFrame.在最后一个面板中,有另一个面板和一个按钮.该小组是我的扩展JPanel,DrawPanel.Rectangle每次单击Repaint下面的按钮时,它会随机绘制.这是我的代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Tester
{
public static DrawPanel panelEastDrawPanelCenter;
public static void main()
{
Tester gui = new Tester();
gui.go();
}
public void go()
{
JFrame frame = new JFrame("This is the title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create all the Western Panel components
JPanel panelWest = new JPanel();
// panelWest.setLayout(new BorderLayout());
JButton panelWestButtonWest = new JButton("Western-most West Button");
JButton panelWestButtonCenter = new JButton("Western-most Center …Run Code Online (Sandbox Code Playgroud) 我正在学习java并且有一些我想写的代码应该在24.9999999到25之间.相反,它会变为8.
import java.io.*;
import java.util.*;
public class RadiusOfCircle
{
public static void main(String args[])
{
Scanner kbInput = new Scanner(System.in);
System.out.print("What is the area? _");
double area = kbInput.nextInt();
System.out.println("Radius of your circle is " + Math.sqrt( area / Math.PI));
double radius = Math.sqrt( area / Math.PI);
System.out.println("\nChecking your work now...\n area = pi*(r^2)\n " + area + " = 3.14 * (" + radius + ")^2");
double radiusSqrd = Math.pow(radius, 2);
System.out.println(" " + area + " = 3.14 …Run Code Online (Sandbox Code Playgroud) 我经常看到形式的结构
struct Employee {
int age;
char* name;
}
Run Code Online (Sandbox Code Playgroud)
我正在为Winsock 2看微软的"入门",看到了这个:
struct addrinfo *result = NULL,
*ptr = NULL,
hints;
ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
Run Code Online (Sandbox Code Playgroud)
这是什么结构?我的数字结构的名字addrinfo,但后来是什么类型的*result,*ptr或hints?
另外,如果之前从未编码过,该如何hints给出.ai_family/socktype/protocol?
我正在尝试获取外语文本并输出人类可读的文件名安全等价物。环顾四周后,似乎最好的选择是unicodedata.normalize(),但我无法让它工作。我试过把一些答案中的确切代码放在这里和其他地方,但它一直给我这个错误。当我运行时,我只获得了一次成功:
unicodedata.normalize('NFD', '\u00C7')
'C\u0327'
Run Code Online (Sandbox Code Playgroud)
但每隔一段时间,我都会收到一个错误。这是我尝试过的代码:
unicodedata.normalize('NFKD', u'\u2460') #error, not sure why. Look same as above.
s = '??? ?????'
unicodedata.normalize('NKFC',s) #error
unicodedata.normalize('NKFD', 'ñ') #error
Run Code Online (Sandbox Code Playgroud)
具体来说,我得到的错误是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid normalization form
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这不起作用。所有这些都是字符串,这意味着它们在 Python 3 中是 unicode。我尝试使用 对它们进行编码.encode(),但后来normalize()说它只需要字符串参数,所以我知道那不可能。我真的很茫然,因为即使是我从这里复制的代码似乎也出错了。这里发生了什么?
我正在学习如何使用open(file, 'r')并且想知道:
如果我说open(file1, 'r'),然后再尝试open()再次使用相同的文件,它会工作吗?因为我从来没有这样做过close().它是否在打开后立即关闭,因为它没有分配给任何变量?
我正在学习HTML/CSS并决定试试这个:
<p>A paragraph with no margins specified.</p>
<div style="width=300px; height=300px; background-color:yellow;><p>This paragraph is in a divider.</p></div>
<p>A paragraph with no margins specified.</p>
Run Code Online (Sandbox Code Playgroud)
经过一些谷歌搜索,我发现你不能改变内联元素的宽度/高度.所以我尝试使用<div>和<p>使用块元素display:block,但这并没有改变任何东西.宽度在屏幕外无限延伸,高度仅与屏幕一样高<p>.我希望有<p>一个300x300 <div>,所以我怎么能这样做?另外,为什么这些方法都不起作用(即使我改为display:block)?谢谢.
另外,我知道你不应该像我一样使用过多的CSS.这只是因为我正在使用W3的"自己动手"HTML编辑器测试内容.
我正在尝试创建一个名为的类Drone,并有两个文件,Drone.h和Drone.cpp.
Drone.h
class Drone {
protected:
void foo();
};
Run Code Online (Sandbox Code Playgroud)
Drone.cpp
#include "Drone.h"
Drone::Drone() // <---ERROR
{
}
void Drone::foo()
{
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
"班级'无人机'没有成员无人机."
当我将鼠标悬停在无人机上时,在工具提示中.在编译器中,它给出了错误:
错误C2600:'Drone :: Drone':无法定义编译器生成的特殊成员函数(必须先在类中声明)
为什么是这样?我所要做的就是为Drone制作一个构造函数.
我正在学习如何使用ArrayLists并决定尝试制作一个ArrayList.我发现我能做到:
ArrayList<Object> list = new ArrayList<Object>();
list.add("Hi");
list.add(new Integer(5), 9);
Run Code Online (Sandbox Code Playgroud)
(而且我意识到我可以添加一个int,它会自动将它封装)
问题是我不能在指定的索引处放置一个double或Double的ArrayList,我可以用Integer.我试过这样的:
list.add(new Double(4)); // I just redid it, and this one works.
list.add(45.6); // So does this one.
list.add(new Double(4), 6); // it's this one that doesn't.
list.add(43.6, 9); // doesn't work either
Run Code Online (Sandbox Code Playgroud)
所以双打确实适合ArrayList,但你不能指定他们应该在的索引.如果您尝试,结果的错误是:
no suitable method found for add(double, int)
method java.util.ArrayList.add(int,java.lang.Object) is not applicable
(actual argument double cannot be converted to int by method invocation conversion)
method java.util.ArrayList.add(java.lang.Object) is not applicable
(actual and formal argument lists differ …Run Code Online (Sandbox Code Playgroud) 我已经查看了这段代码一段时间,计算括号,所有这些东西.我找不到错误.我正在使用Eclipse,为Android开发,它要求分号(注释,它接近底部).
package com.example.lesson1;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class TextPlay extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
final Button checkCommand = (Button) findViewById(R.id.bResults);
final ToggleButton passToggle = (ToggleButton) findViewById(R.id.tbPassword);
final EditText input = (EditText) findViewById(R.id.etCommands);
final TextView display = (TextView) findViewById(R.id.tvResults);
passToggle.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (passToggle.isChecked()) {
input.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
checkCommand.setOnClickListener(new View.OnClickListener() …Run Code Online (Sandbox Code Playgroud) 我是C/C++的新手,我正在学习数组.我刚刚读完了关于将数组传递给函数的内容,并且正在尝试实现它.我从一个数组开始x[] = "Hello,当然有一个sizeof()6.但由于某种原因,当我将它传递给我的函数时listElements(char arr[]),我得到sizeof(arr)等于4.为什么我的数组被切断了?
另外,sizeof(char)我的编译器是1.
#include <iostream>
using namespace std;
void listElements(char[]);
int main(){
char x[] = "Hello";
cout << sizeof(x) << endl; // 6
listElements(x);
cin >> x[0];
return 0;
}
void listElements(char arr[]){
cout << "Size of arr: " << sizeof(arr) << endl; // 4 <--- why is this 4?
cout << "Size of char: " << sizeof(char) << endl; // 1
for (int j = 0; j …Run Code Online (Sandbox Code Playgroud)