• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pythagorean theorem

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(System.in);

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\Hypotenuse.java

Hypotenuse.java:3: class Hypontenuse is public, should be declared in a file named Hypontenuse.java
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?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Henry
 
Tim Schmidt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it worked!
 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic