C++ では cin を使いますよね。 標準入力ストリームを使うわけです。
Java では標準入力は System.in です。しかし、です。このままでは使えないんですね。
以下の F1 Score 計算プログラムでは Scanner を使用しています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class FValueScanner | |
{ | |
public static void main(String args[]) | |
{ | |
String str; | |
try | |
{ | |
Scanner kbd=new Scanner(System.in); | |
System.out.print("True-Positive: "); | |
double truePos=kbd.nextDouble(); | |
System.out.print("False-Positive: "); | |
double falsePos=kbd.nextDouble(); | |
System.out.print("True-Negative: "); | |
double trueNeg=kbd.nextDouble(); | |
System.out.print("False-Negative: "); | |
double falseNeg=kbd.nextDouble(); | |
double precision=truePos/(truePos+falsePos); | |
System.out.println("Precision="+precision); | |
double recall=truePos/(truePos+trueNeg); | |
System.out.println("Recall="+recall); | |
double f=2*precision*recall/(precision+recall); | |
System.out.println("F1="+f); | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |