我正在为这个项目工作一个小时,我仍然无法找到解决方案。我总是得到同样的错误(EnigmaEncrypt.java:44:错误:不兼容的类型:从float到char的可能有损转换 char e = exampleCharInput; ^ 1错误) 这是我的代码:
import java.util.Scanner;
// Created by ab38 on 2015-12-01.
public class EnigmaEncrypt {
// Static Scanner field
private static Scanner scan;
/**
* Get a char from the command line.
*
* @return the first char of the current line, typed by the user
* on the command line.
*/
private static char getChar() {
return scan.next().charAt(0);
}
/**
* Get an integer from the command line.
*
* @return the integer on the current line, typed by the user
* on the command line.
*/
private static int getInt() {
return scan.nextInt();
}
public static void main(String[] args) {
scan = new Scanner(System.in);
// Example: How to get an integer from the command line:
System.out.println("Enter an integer:");
int exampleIntInput = getInt();
System.out.println("Rotorposition: " + exampleIntInput);
// Example: How to get a single char from the command line:
System.out.println("Enter a single character:");
float exampleCharInput = getChar() + exampleIntInput;
char e = exampleCharInput;
System.out.println("Char from command line: " + e);
}
}
答案 0 :(得分:0)
char以2字节存储,浮动4字节。你试图在不进行投射的情况下将浮点数放入char中。试试这个
function loadProductActionCreator(dispatch) {
dispatch({
type: 'load_product',
})
fetch('api/product').then(
function (r) {
return r.json();
}
)
.then(function (res) {
dispatch({
type: 'loaded_product',
data: res
})
})
}