这段代码没有语法错误,但是当我放置浮点值时会得到InputMismatchException。双值而不是float则得到相同的异常。如果以F.f格式输入每个值(带有点),则会出现异常。如果输入值为1,9值(逗号),则此代码有效。为什么?
Scanner l = new Scanner(System.in);
String n;
int i;
float a;
System.out.print("N: ");
n = l.nextLine();
System.out.print("I: ");
i = l.nextInt();
System.out.print(&
我正在将数据从Excel文件导入到Server。我的工作表包含一些日期时间列。如果它包含'M/d/yyyy'(12/31/2015)格式(也就是我的系统日期时间格式)的值,那么它将顺利执行,不会出现任何错误。但是对于'M/d/yyyy‘格式以外的值,它不会插入数据并给出异常。
我甚至不会将日期时间值转换成特定的格式,然后插入,只需将数据插入到Server。我无法理解问题到底是什么,以及它与系统日期时间格式有什么关系。
我使用的代码是:
select case when ISDATE(@SignalDateTime)=1 then @SignalDateTime else
看到的Double.java源代码和一些常量如下
/**
* Constant for the Not-a-Number (NaN) value of the {@code double} type.
*/
public static final double NaN = 0.0 / 0.0;
/**
* Constant for the positive infinity value of the {@code double} type.
*/
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
/**
* Con
我刚刚开始学习Java编程,我不知道如何将用户输入的值存储为double。
下面是我的代码:
package FirstProject;
import java.util.Scanner;
public class TripPlanner {
public static void main () {
Scanner console = new Scanner(System.in);
System.out.print("How many
我有一段代码工作得很好,现在不知怎么不起作用了。
我正在读取一个csv文件,在读取4:38格式的时间字段时会出现错误。
我抛出异常的代码是:
LocalTime.parse("4:38", DateTimeFormatter.ofPattern("HH:mm"))
我也尝试了"H:mm"或"H:m"的模式,但它抛出了相同的异常:Text '4:38' could not be parsed at index 0。知道为什么它会在小时数抛出异常吗?
我正在使用Java 8。
我期望为下列代码和输入抛出异常:
SimpleDateFormat getDateTimeFormat(String requiredFormat)
{
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(requiredFormat);
//this will make sure that if parsing fails exception is thrown
dateTimeFormat.setLenient(false);
return dateTimeFormat;
}
Date date =
下面这段代码到底做了什么,
//Make the year be formatted without a thousands separator.
spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));
为什么这是消除JSpinner numberModel中的逗号所必需的。
我刚开始使用java,请用简单的术语来解释。
我正在尝试从字符串中提取一个数字并对其执行操作。这是我正在编写的相关代码(更新):
String cardNumber;
String curNum;
long currentNum;
int firstNum;
int randNum;
int i;
long sum = 0;
while (i <= 15) {
//Delete this line if it doesnt work
currentNum = Long.parseLong(cardNumber.substri
我试图从属性文件中加载信息,我有以下代码:
int minute = Integer.parseInt(prop.getProperty("delay"));
int hour = Integer.parseInt(prop.getProperty("period"));
虽然第一行工作得很好,但是第二行(我试图加载一个int变量)抛出了一个NumberFormatException。具体的例外消息是:
java.lang.NumberFormatException: For input string: "1 "
at java.lang
我试图取下下面的文本文件,只取第一列的数字,以求平均值。但是,我甚至无法获得要打印的数字,因为文本文件中也有字符串出现在双字符之前,这使得我的nextLong()立即失败。到目前为止,我掌握的代码如下:
import java.io.*;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
public class cancer{
public static void main(String[] args) t
一个朋友和我正在做一个简单的游戏,它随机选择其中一个名字,用户必须猜测它,直到他/她得到正确的。,但是我们收到一个错误:在线程"main“java.lang.NumberFormatException: For input:"Adam”中出现异常。有人能帮忙吗?
package projectpackage;
import java.util.Random;
import java.util.Scanner;
public class ProjectClass {
public static void main(String eth[]) {
int ad
我有一个文本文件,从中读取和设置事务POJO类数据,以获得开始时间和结束时间之间的差异,我需要解析date对象中的时间信息。
DateFormat format = new SimpleDateFormat(dateFormat);
System.out.println("Date format in play:"+dateFormat);
Transaction transaction = storageRepositroy.getTransaction(key);
Date start = format.parse(transaction.getStartDate() +
我为我的删除按钮写了这些行。我没有出现错误,但是按钮什么也不做,有时我从vb中得到这个错误
类型为'System.FormatException‘的未处理异常出现在“mscorlib.dll”中,其中包含代码“c.patientID =Convert.ToInt32(txtBoxPatientID.Text)”中的一个选择;
知道我怎么才能让我的删除按钮工作吗?
private void btnSupprimer_Click(object sender, EventArgs e)
{
// Get Patient ID from app
c.patientID = C
你好,伙计们,我在执行这段代码时出错了--它在我的电脑中运行得很好--但是当我把这个应用程序发送给我的朋友去尝试时,它导致了一个数字格式的异常,代码有问题吗?如果是这样的话,为什么它在我的计算机上工作? ps:我在另一台计算机上尝试了这个应用程序,它可以工作。
double total = 0;
//here there is a for loop changing the total value
//but in this case (when the application starts) the loop condition will be false
//so the total w
我想在Java中用一定数量的小数位来格式化一个双精度数。我的代码目前看起来像这样:
final NumberFormat format = NumberFormat.getInstance();
format.setMinimumFractionDigits(decimalPlaces);
format.setMaximumFractionDigits(decimalPlaces);
format.setGroupingUsed(false);
String s = format.format(value);
但是当decimalPlaces大于340时