我正在尝试读取CSV文件,并通过java中的二维数组将每一行拆分为4个不同的整数值.
我正在使用openCSV 3.8.
为简单起见,请说这是CSV文件的内容(完整文件包含306行,就像这些):
76,67,0,1
77,65,3,1
78,65,1,2
83,58,2,2
Run Code Online (Sandbox Code Playgroud)
我可以正常读取文件,我可以用来System.out.println将每个单独的值输出到控制台,如下所示:
76
67
0
1
77
65
3
1
78
65
1
2
85
58
2
2
Run Code Online (Sandbox Code Playgroud)
不幸的是,我的代码设计为将每个值输入到一个单独的数组元素中,只将4个值保存在文件的最后一行.
这是我的java代码(不介意iaData数组的大小,它的大小适合完整的CSV文件):
public static void main(String[] args) {
//String outputStr = "";
int[][] iaData = new int[306][4];
int i = 0;
int x = 0;
try
{
//Get the CSVReader instance with specifying the delimiter to be used
CSVReader reader = new CSVReader(new FileReader("haberman.data"),',');
String [] nextLine = new String[1250];
//Read …Run Code Online (Sandbox Code Playgroud) 遇到一个问题,return View(await _context.Reviews.ToListAsync);出现以下错误:Cannot await 'method group'
我相信要使用该return View(await _context.Reviews.ToListAsync);语句,我需要使用using ASPNETCoreWebApplication.data(因此我包含它),但它返回一个错误:The type or namespace 'ASPNETCoreWebApplication' could not be found [...]。
如果我删除using <project_name>data,则会出现与上面ApplicationDbContextin相同的HomeController.cs错误
以下是我的HomeController.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ASPNETCoreWebApplication.Data; // "The type or namespace 'ASPNETCoreWebApplication' could not be found [...]"
using <project_name>.Data;
using Microsoft.EntityFrameworkCore;
namespace <project_name>.Controllers
{
public class HomeController : Controller
{
private readonly ApplicationDbContext _context;
public …Run Code Online (Sandbox Code Playgroud) Eclipse Java IDE在使用continue语句时遇到问题时出错:
double sum = 0.0;
double avg = 0.0;
for (i=0 ; i<daRun1.length ; i++);
{
if(daRun1[i] == max || daRun1[i] == min)
{
continue; //<-- **this is where the error is showing (underlined in red in eclipse)**
}
sum += daRun1[i];
}
avg = sum / (daRun1.length-2);
System.out.println("The average score is: " + avg);
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?这个确切的if循环用于演示,没有任何问题.