我在Eclipse中编写了这个Java接口程序,但在MyTriangle下面有一个红线tmp = new MyTriangle(); 当我运行程序时,我收到此错误:
不能访问Question1类型的封闭实例.必须使用Question1类型的封闭实例限定分配(例如,xnew A(),其中x是Question1的实例).
public static void main(String[] args)
{
MyTriangle tmp = new MyTriangle();
tmp.getSides();
System.out.println();
System.out.println("The area of the triangle is " + tmp.computeArea());
}
interface Triangle
{
public void triangle();
public void iniTriangle(int side1, int side2, int side3);
public void setSides(int side1, int side2, int side3);
public void getSides();
public String typeOfTriangle();
public double computeArea();
}
class MyTriangle implements Triangle
{
private int side1,side2,side3;
public void triangle()
{
this.side1 = 3; …Run Code Online (Sandbox Code Playgroud) 我试图想出一个将经历一个弹簧的循环,一旦它到达%字符,它就会将%之后的所有内容传递给hexToInt函数.这就是我想出来的.
for(int x=0; x<temp.length(); x++)
{
if(temp.charAt(x)=='%')
{
newtemp = everthing after '%'
hexToInt(newtemp);
}
}
Run Code Online (Sandbox Code Playgroud) 我想检查一下用户是否?在缓冲区的末尾添加了一个.如果没有,我希望程序自动添加一个.这就是我到目前为止所拥有的.我不知道接下来该做什么.
首先,我检查缓冲区是否为空白.
然后,如果最后一项不是a ?,则将问号自动添加到缓冲区,然后将内容复制到当前数据节点.
if ( strlen(buffer) != 0)
{
if (buffer[strlen(buffer)-1] != '?')
{
//what do i put here to add the ? if theres non?
}
strcpy(current->data,buffer);
}
Run Code Online (Sandbox Code Playgroud) 我有一个已排序的链表,我试图创建一个函数来删除用户传递给nameToSearch的任何内容.但我一直在犯错.以下是我到目前为止的情况
void deleteProduct(NodePtr head, char* nameToSearch)
{
NodePtr nodeUnderEdit = findNodeByName(head, nameToSearch);
if (nodeUnderEdit == NULL)
{
cout<<"\n ERROR: Product not found \n";
}
else
{
delete nodeUnderEdit;
nodeUnderEdit = nodeUnderEdit->next;
}
}
Run Code Online (Sandbox Code Playgroud) 这是我第一次使用java界面而且非常困惑.在线阅读教程之后,我就会想到如何定义界面并实现它,但是小时,分钟和秒都有红色下划线.我无法弄清楚为什么会如此.
interface myClock {
int hours;
int minutes;
int seconds;
public void clock();
public void clock(int x, int y, int z);
public void setTime(int x, int y, int z);
public void incTimeBySec();
public void incTimeByMins(int x);
public void display12hr();
public void display24hr();
}
class time implements myClock {
public void clock() {
hours = 0;
minutes = 0;
seconds = 0;
}
public void clock(int x, int y, int z) {
hours = x;
minutes = y;
seconds = z; …Run Code Online (Sandbox Code Playgroud)