Primatives
// java style to import library
import java.util.Scanner;
double mass;
double accel;
double Force;
double ac;
double m;
// class must alway have 1st letter as uppercase, CamelCase is Java Class convention
public class ScanPrimitives {
public static void main(String[] args) {
Scanner input;
// primitive int
input = new Scanner(System.in);
System.out.println("F=ma calculator");
System.out.println("Enter the mass: ");
try {
double mass = input.nextDouble();
System.out.println(mass);
m = mass;
} catch (Exception e) { // if not an integer
System.out.println("Not an integer (form like 159), " + e);
}
input.close();
// primitive int
input = new Scanner(System.in);
System.out.print("Enter the accel: ");
try {
double accel = input.nextDouble();
System.out.println(accel);
ac = accel;
} catch (Exception e) { // if not an integer
System.out.println("Not an integer (form like 159), " + e);
}
input.close();
System.out.println("Force calculator");
double Force = m * ac;
System.out.print(m + "*" + ac + '=' + Force);
}
}
ScanPrimitives.main(null);