This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Pythagorean theorem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pythagorean theorem" Watch "Pythagorean theorem" New topic

Pythagorean theorem

Tim Schmidt

Joined: Mar 05, 2009
Posts: 6
I'm trying to make a program where the command line accepts input from the keyboard to use for the sides of a triangle, the program then should calculate the hypotenuse and print it.

heres my code:

import java.util.Scanner;

public class Hypontenuse
public static void main(String[] args)
Scanner keyboard = new Scanner(;

double side1;
double side2;

System.out.println("Enter Side 1");
side1 = keyboard.nextFloat();

System.out.println("Enter Side 2 ");
side2 = keyboard.nextFloat();

System.out.print(Math.sqrt(side1*side1 + side2*side2));

I get the error message:

----jGRASP exec: javac -g C:\Documents and Settings\User\My Documents\ class Hypontenuse is public, should be declared in a file named
public class Hypontenuse
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

What am I doing wrong? is there a better way to code this?
Henry Wong

Joined: Sep 28, 2004
Posts: 19344

Take a look at your filename again -- you mis-spelled it. The filename and the class name are not the same.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tim Schmidt

Joined: Mar 05, 2009
Posts: 6
Thanks, it worked!
I agree. Here's the link:
subject: Pythagorean theorem