View Full Version : Help with a Java program
the.dark.lord
March 2nd, 2007, 09:33 AM
Can anyone translate this Java program written for Windows into Mac language? Thanks in advance.
import java.io.*;
public class areasquarerect
{
public static void main(String[] args) throws IOException
{
BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in));
String instr;
double l,b,a;
l=b=a=0;
System.out.println("enter the length of a side of a square: ");
instr=keyin.readLine();
a=Double.parseDouble(instr);
System.out.println("enter the length a rectangle: ");
instr=keyin.readLine();
l=Double.parseDouble(instr);
System.out.println("enter the breadth of a rectangle : ");
instr=keyin.readLine();
b=Double.parseDouble(instr);
System.out.println("area of square = "+(4*a*a));
System.out.println("area of rectangle = "+(2*(l+b)));
}
}
lnostdal
March 2nd, 2007, 10:06 AM
sure, here:
import java.io.*;
public class areasquarerect
{
public static void main(String[] args) throws IOException
{
BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in));
String instr;
double l,b,a;
l=b=a=0;
System.out.println("enter the length of a side of a square: ");
instr=keyin.readLine();
a=Double.parseDouble(instr);
System.out.println("enter the length a rectangle: ");
instr=keyin.readLine();
l=Double.parseDouble(instr);
System.out.println("enter the breadth of a rectangle : ");
instr=keyin.readLine();
b=Double.parseDouble(instr);
System.out.println("area of square = "+(4*a*a));
System.out.println("area of rectangle = "+(2*(l+b)));
}
}
lars@ibmr52:~/programming/java$ javac areasquarerect.java
lars@ibmr52:~/programming/java$ java areasquarerect
enter the length of a side of a square:
2
enter the length a rectangle:
4
enter the breadth of a rectangle :
5
area of square = 16.0
area of rectangle = 18.0
oh, and it works on linux too .. so both windows, linux and mac then
Ramses de Norre
March 2nd, 2007, 12:06 PM
Can anyone translate this Java program written for Windows into Mac language? Thanks in advance.
I think you're missing one of the most important features of java: it's platform independent.
If you use only standard classes (or other well designed classes) your program will run on every computer which has a jre installed.
the.dark.lord
March 2nd, 2007, 05:14 PM
Thanks Ramses adI'm quite new to programming, I know it is was platform independent. But, it wouldn't work when I tried it out on this iMac. Does mac has JRE installed by default?
maxamillion
March 2nd, 2007, 05:18 PM
Thanks Ramses adI'm quite new to programming, I know it is was platform independent. But, it wouldn't work when I tried it out on this iMac. Does mac has JRE installed by default?
Yes, OS X comes with Java by default.
Ramses de Norre
March 2nd, 2007, 05:20 PM
Why didn't it work? Because it didn't found the java executable or because it threw an exception?
If java -version returns somethings and it's not an error you've got a JRE.
the.dark.lord
March 2nd, 2007, 05:24 PM
Hey, I got it working now. :) :) :). You've been great people, thanks for the help.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.