小编Ren*_*Ren的帖子

Java错误和语法教程

我正在寻求自助方面的帮助,这是一种矛盾.如何通过解决更多我自己的问题来减少你的好人?

我是Java编程的最后一周,我在学习Java方面面临巨大障碍.我已经阅读了所有的书籍,但我仍然在小小的问题上陷入困境.这就像试图建立一个纸牌屋.我只知道语法的各个部分以及本书所展示的用途.当我把事情结合起来时,我遇到了可怕的障碍.我试着花几个小时来修补它们.sun文档仅显示似乎没有帮助的基本用法

这就是我想要的:

当我尝试某些东西并且它不像下面对数组列表的操作那样工作时,我想找到一个可以显示示例代码的地方或程序,例如向arrayList添加一个额外的类实例.哪里可以简明扼要地学习这一点,而不必为每个语法错误提出问题或2?Google for Java在哪里?是否有一个程序可以解决您的错误并向您展示如何修复它们(或提供建议)?

/tmp/jc_4083/Inventory.java:101: incompatible types
found   : RatedDVD[]
required: java.util.ArrayList
        dvdlist = temp;
                  ^
/tmp/jc_4083/Inventory.java:110: array required, but java.util.ArrayList found
            if (p != dvdlist[i]) {
                            ^
/tmp/jc_4083/Inventory.java:111: array required, but java.util.ArrayList found
                temp[i-adj] = dvdlist[i];
                                     ^
/tmp/jc_4083/Inventory.java:115: incompatible types
found   : RatedDVD[]
required: java.util.ArrayList
        dvdlist = temp;
Run Code Online (Sandbox Code Playgroud)

如果有人有兴趣为我查看它,这是我的这个类的代码:

//Contruct inv and allow for methods add, get, size, sort, and value
import java.util.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class Inventory
{// class Inventory
    private ArrayList<RatedDVD> …
Run Code Online (Sandbox Code Playgroud)

java compiler-errors arraylist

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

C编程.如何制作打印字符串的方法

我试图在C中创建一个函数,它将打印一个作为参数的字符串.这在C中甚至可能吗?

我的头文件中有这样的东西,但字符串不是有效的标识符.我知道C中没有字符串,但是string.h类是什么?

#include <string.h>    

#ifndef _NEWMAIN_H
#define _NEWMAIN_H

#ifdef __cplusplus
extern "C" {
#endif

    void print (string message){  //this is where i need help
        printf("%s", message);
    }


#ifdef __cplusplus
}
#endif

#endif /* _NEWMAIN_H */
Run Code Online (Sandbox Code Playgroud)

c string

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

将新元素插入已排序的链接列表时的Segfault

我使用以下函数将新节点插入到排序的整数链表中

 // Insert new element
template <class Type>
bool list<Type> :: Insert (const Type& NewElement)
{
    Node *NewNode, *TempNext, *TempPrevious;
    NewNode = new Node;
    NewNode -> Element = NewElement;

    for (TempNext = Head; TempNext != NULL; TempPrevious = TempNext, TempNext = TempNext -> Next) 
    {
        NewNode -> Next = TempNext;
        if (TempNext == Head) Head = NewNode; // Check for empty list
        else if (NewNode -> Element >= TempNext -> Element) continue; // Check for correct point in list
        else …
Run Code Online (Sandbox Code Playgroud)

c++ linked-list data-structures

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

C从文件中读取多行

我遇到的问题是使用标准输入从文件中读取多行整数.文件看起来像:

123
423
235
523
..etc
Run Code Online (Sandbox Code Playgroud)

我目前的代码是:

/*
 * Read in the initial puzzle configuration.
 * Each line is 4 characters long:
 *   Row    as a character '0' .. '9'
 *   Column as character '0' .. '9'
 *   Digit  as character '0' .. '9'
 *   Terminating newline.
 * Exits with an error message if there are syntactic
 * or semantic errors with any configuration line.
 */

void configure(FILE *puzzle_file) {
        int row;
        int column;
        int value;

        while((fscanf(puzzle_file, "%i%i%i\n", row, column, …
Run Code Online (Sandbox Code Playgroud)

c scanf stdio

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

我的'cout'没有给出正确的价值 - 为什么?

简单的"数字和"代码.它编译但是在执行时,最后一个cout为num int而不是实际的用户输入数字给出"0".

如果您愿意,可以随意将其复制并粘贴到您自己的编译器中,看看我的意思.

如何输出正确的"num"值?

~~~

#include <iostream>

using namespace std;

int main()
{
  int num;
  int sum = 0;

  cout << "Please type any non-negative integer: ";
  cin >> num;

  while ( num > 0 ) {
    sum += num % 10;
    num /= 10;
  }

  cout << "The sum of the digits of " << num << " is " << sum << "\n";

  system("PAUSE");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ sum-of-digits

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

如何在运行时从JTextArea运行/编译Java代码?

我有一个JInternalFrame,它绘有BufferedImage并包含在JFrame的JDesktopPane中.我还有一个JTextArea,我想编写一些java代码(函数),它将当前JInternalFrame的绘制BufferedImage作为输入,在对此输入进行一些操作后,它返回另一个操作的BufferedImage,它再次使用新的操作Image绘制JInternalFrame.

操纵JTextArea的java代码: -

public BufferedImage customOperation(BufferedImage CurrentInputImg) 
{    
    Color colOld;
    Color colNew;

    BufferedImage manipulated=new BufferedImage(CurrentInputImg.getWidth(),CurrentInputImg.getHeight(),BufferedImage.TYPE_INT_ARGB);

    // make all Red pixels of current image black 
    for(int i=0;i< CurrentInputImg.getWidth();i++) {
        for(int j=0;j< CurrentInputImg.getHeight(),j++) { 
            colOld=new Color(CurrentInputImg.getRGB(i,j));
            colNew=new Color(0,colOld.getGreen(),colOld.getBlue(),colOld.getAlpha());
            manipulated.setRGB(i,j,colNew.getRGB());
        } 
    }

    return manipulated;
}
Run Code Online (Sandbox Code Playgroud)

如何在运行时运行/编译此JTextArea Java代码并获取一个新的操作图像以便在JInternalFrame上绘制?

这是我的主要课程:

(这个类不是实际的,但是我为你创建了它,用于包含JTextArea,JInternalFrame,Apply Button的基本接口)

import java.awt.*;    
import java.awt.event.*;    
import javax.swing.*;    
import javax.swing.event.*;    
import javax.swing.JInternalFrame;    
import javax.swing.JDesktopPane;    
import java.awt.image.*;    
import javax.imageio.*;    
import java.io.*;    
import java.io.File;    
import java.util.*;

class MyCustomOperationSystem extends JFrame    
{

    public JInternalFrame ImageFrame;     
    public BufferedImage …
Run Code Online (Sandbox Code Playgroud)

java bufferedimage runtime compilation

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

递归函数找到素数因子

我做了一个递归函数来找到一个数字的素因子,但是它有一个让turbo c退出的错误.请帮忙

#include<stdio.h>
#include<conio.h>
int prime(int num);
int primefactor(int num,int i);
void main(void)
{
    int num;
    printf("Enter a number whose prime factors are to be calculated:");
    scanf("%d",&num);
    primefactor(num,i);
     i=num 
    getch();
}
int primefactor(int num,int i)
{
    if(i==2)
    return 1;
    if(num%i==0)
    {
        if(prime(num))
        {
            printf(",%d",num);
            num=num/i;
            i++;
        }


    }
    i--;
    primefactor(num,i);
    return 0;
}
int prime(int num)
{
    int i,flag;
    for(i=2;i<num;i++)
    {
        if(num%i==0)
    flag=0;
    }
    return flag;
}
Run Code Online (Sandbox Code Playgroud)

c recursion

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

Java中的堆栈有例外

题 :

b)Stack是后进先出(LIFO)数据结构.编写一个Java类Stacklnt,它使用alray作为私有数据结构来存储整数堆栈.Stacklnt有:

  • 最大大小,在创建Stacklnt对象时设置.如果大小超出10到10的范围,则应抛出异常.1000

  • 方法push,将值添加到堆栈顶部.如果在调用push时堆栈已满,则应抛出异常.

  • 方法pop,用于删除并返回堆栈顶部的值.如果在调用pop时堆栈为空,则应抛出异常.

c)编写一些示例代码,以显示如何使用(b)部分中的类Stacklnt.包括正常使用的示例以及抛出异常的所有情况.

好吧基本上这是一个我试图解决的问题,真的非常感谢一些帮助.

例外情况就是这种形式

// Throw an exception!
public T pop() throws EmptyStackException
{
   if (contents.size() == 0) 
   { throw new EmptyStackException(); } 
   else
   { return contents.remove(0); }
}
Run Code Online (Sandbox Code Playgroud)

我到目前为止:

public class Stack {
  private int top;
  private int[] storage; 

  Stack(int capacity) {
        if (capacity <= 0)
              throw new IllegalArgumentException(
                         "Stack's capacity must be positive");
        storage = new int[capacity];
        top = -1;
  }

  void push(int value) {
        if (top == storage.length)
              throw new StackException("Stack's underlying …
Run Code Online (Sandbox Code Playgroud)

java stack exception

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