Results 1 to 5 of 5
- 03-19-2012, 05:01 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Cannot run Java program in command window
When I try to run a simple program, even HelloWorld.java, the java file opens in NotePad and nothing happens in the command window. Below is one of the programs I tried to run which was copied from a training book.
/*
* SimpleMathTest
* Performs simple mathematical operations on integer and
* double operands
*/
public class SimpleMathTest {
public static void main(String args[]) {
int x = 10,
y = 7;
//be careful not to confuse math operators with string
//operators
System.out.println(x + " + " + y + " = " + (x + y));
System.out.println(x + " - " + y + " = " + (x - y));
System.out.println(x + " * " + y + " = " + (x * y));
System.out.println(x + " / " + y + " = " + (x / y));
System.out.println(x + " % " + y + " = " + (x % y));
//would be more readable with explicit casting
//i.e. double a = (double) x, b = (double) y;
double a = x,
b = y;
System.out.println(a + " + " + b + " = " + (a + b));
System.out.println(a + " - " + b + " = " + (a - b));
System.out.println(a + " * " + b + " = " + (a * b));
System.out.println(a + " / " + b + " = " + (a / b));
System.out.println(a + " % " + b + " = " + (a % b));
//emphasizes that floating point modulus ops can
//result in real numbers
System.out.println("1.1 % 1.0 = " + (1.1 % 1.0));
}
}
- 03-19-2012, 05:42 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Cannot run Java program in command window
What exactly do you type on the cmd?
- 03-19-2012, 05:55 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Cannot run Java program in command window
I type: SimpleMathTest.java, which is what it is named. But even with HelloWorld.java the same thing happens. That is after setting up the environment which now appears as:
C:\Users\Phaeton\Documents\JAVA>SET PATH=C:\Windows\system32;C:\Windows;C:\Windows\Sys tem32\Wbem;C:\jdk1.3.1\bin
- 03-19-2012, 05:58 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Cannot run Java program in command window
Try typing
Also, if you are using java 3 as that path implies, I'd suggest you update your java. Java is on 7 now as opposed to the 3 you seem to be using.Java Code:java SimpleMathTest
- 03-19-2012, 06:03 AM #5
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
command line window on java game
By ki_ha1984 in forum New To JavaReplies: 3Last Post: 08-15-2011, 09:39 PM -
how ro use net share ms dos command) in java program
By adyr in forum NetworkingReplies: 0Last Post: 08-11-2011, 08:17 AM -
Letting my program command the command prompt
By Smokey. in forum Threads and SynchronizationReplies: 4Last Post: 03-29-2011, 11:34 PM -
Calling a JFrame window from a command line program.
By new_2_java in forum New To JavaReplies: 7Last Post: 11-09-2008, 03:40 AM -
Execute a jar command from a java program
By apremanandh in forum New To JavaReplies: 3Last Post: 05-21-2008, 02:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks