小编ed *_*ale的帖子

使用FileReader和Scanner读取文件

我是一个Java初学者,并已阅读类似的问题,但我仍然不知道为什么我的代码显示FileNotFound异常.我的文件在同一目录中.

我的代码是:

import java.io.*;
import java.util.Scanner;

public class reader {
    public static void main(String[] args) { 
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        double y = in.nextDouble();
        float g = in.nextFloat();
        String a = in.next();
        File file = new File("v.txt");
        System.out.println(x + "" + y + "" + g + "" + a); 
        Scanner inFile = new Scanner(new FileReader(file));
        String u = inFile.nextLine();
        System.out.println(file.getAbsolutePath());
        System.out.println(u);
    }
}
Run Code Online (Sandbox Code Playgroud)

错误是:

17: error: unreported exception FileNotFoundException; must be caught or declared …
Run Code Online (Sandbox Code Playgroud)

java file java.util.scanner

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

在C++中将2d数组作为函数参数传递出错

我试图将2d数组传递给函数但编译器显示错误:

错误:无法转换int (*)[5]int**的参数1int max_size(int**, int, int)

我知道这个理论但却无法弄清楚它为什么不起作用.

    #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define r 6
#define c 5

using namespace std;

int max_size(int *g[],int m,int n)
{
    // Initial Structure for DP
    int i,j;
    int **s = (int **) malloc (r*sizeof(int *));
    for(i=0;i<r;i++)
        s[i]=(int *)malloc(c*sizeof(int));
    memset(s,0,sizeof(s));

    // Initialization for DP
    for(i=0;i<r;i++)
        s[i][0] = g[i][0];
    for(i=0;i<c;i++)
        s[0][i] = g[0][i];

    // Formulation for DP

    for(i=1;i<r;i++)
    {
        for(j=1;j<c;j++)
        {
            if(g[i][j])

                s[i][j]= min(s[i-1][j],s[i-1][j-1],s[i][j-1])+1;

            else …
Run Code Online (Sandbox Code Playgroud)

c++ arrays 2d function

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

C++中的运行时错误

我在运行良好的代码块上运行此程序,但在在线判断中,它为输入相同的输入提供运行时错误.我无法弄清楚这个错误的原因是什么.

    vector<int> twoSum(vector<int> &numbers, int target)
    {

     vector<int> c ;

    sort(numbers.begin(),numbers.end()-1);

    vector<int>::iterator i = numbers.begin();
    vector<int>::iterator j = numbers.end()-1;

    while(i<=j)
    {
        int sum = *i + *j;
        if(sum==target)
                           { c.push_back(i-numbers.begin());
                             c.push_back(j-numbers.begin());
                             //cout<<*i<<" "<<*j<<endl;
                             break;

                           }
        else if(sum<target) i++;
        else j--;
    }
    return c;
}
Run Code Online (Sandbox Code Playgroud)

c++ runtime-error vector

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

标签 统计

c++ ×2

2d ×1

arrays ×1

file ×1

function ×1

java ×1

java.util.scanner ×1

runtime-error ×1

vector ×1