javac HelloWorld.java java HelloWorld
import sys import math # Define speed of light as constant C. # The units are km/sec. C = 2.998e5 m0 = input("Enter rest mass: ") if m0 < 0: print("Rest mass must be nonnegative.") sys.exit( ) v = input("Enter velocity: ") if v > abs(c): print("Velocity cannot be > c.") sys.exit( ) m = m0 / Math.sqrt(1 - (v / c) ** 2) print("Relativistic mass is", m) // Here is the translated Java version: import java.util.Scanner; public class Relativity { public static void main(String[ ] args) { Scanner input = new Scanner(System.in); final double c = 2.998e5; System.out.println("Enter rest mass: "); double m0 = Double.parseDouble(input.nextLine( )); if (m0 < 0) { System.out.println("Rest mass must be nonnegative."); System.exit(0); } System.out.println("Enter velocidy: "); double v = Double.parseDouble(input.nextLine( )); if (v > c) { System.out.println("Velocity must be < c."); System.exit(0); } m = m0 / Math.sqrt(1 - Math.pow(v / c, 2)); System.out.println("Relativistic mass is " + m + ".") } }
cel = int(input('Input a Celsius temperature: ')) fahr = 9 * cel / 5 + 32 print('Fahrenheit temperature: ', fahr)Translate this script into Java and test it in a Shell script and in the Tutorials Point Online Compiler. ,
DOS | Unix | Meaning |
---|---|---|
cd | cd | Change directory. |
cls | clear | Clear Screen. |
copy | cp | Copy file or directory. |
del | rm | Delete file. |
dir | ls | List files in current directory. |
echo | echo | Echo a string to the DOS Command or Terminal Window. |
exit | exit | Close the DOS Command or Terminal Window. |
java | java | Execute Java executable file. |
javac | javac | Compile Java source code file. |
py | py | Execute Python source code file. |
mkdir | mkdir | Make new directory. |
rmdir | rmdir | Remove directory. |
rename | mv | Rename file or directory. |
type | cat | Type file to the screen. |
57 -325 0 567654 2000000000
3.546 -32.234 5.98e24 9.11e-31
'A' 'y' '8' '*' ' ' '\n'
'\n' '\t' '\v' '\r' '\f' '\\' '\'' '\"' '\0'
'\a' (audible bell)
"elephant" "@#$%^&*)(" "345" "" "This\nis\na\ntest.\n"
true false
int n, m; double x, y; char a, b; String s, t, u; n = 342; m = -81; x = 23.432; y = -76.312; a = 'A'; b = 't'; s = "Hello, World!";
int n = 342, m = -81; float x = 23.432, y = -76.312; char a = 'A', b = 't'; String s = "dog", t = "cat", u = "";
Datatype | Meaning | Size in Bytes | Minimum | Maximum | Significant Digits |
---|---|---|---|---|---|
byte | Integer | 1 | -128 | 127 | |
short | Integer | 2 | -32,768 | 32,767 | |
*int | Integer | 4 | -2.1×109 | 2.1×109 | |
long | Integer | 8 | -9.2×1018 | 9.2×1018 | |
float | Floating Point | 4 | -3.4×1038 | 3.4×1038 | 7 |
*double | Floating Point | 8 | -1.8×10308 | 1.8×10308 | 15 |
*char | Character | 2 | Any Unicode Character | ||
*boolean | Logical | 1 | false | true |
// Long method: String s = new String("dog"); // Short method: String s = "dog";
+ - % = == < <= > >= != & | ^ ~ += -= *= /= &= |= ^=