• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Working on a program challenge for my class and having some trouble

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to create a code that allows the user to input a three letter triangle name, then it state the name of the triangle and the angles. Then the code is meant to ask for length a and b, the angle of X, and calculate all of the angle degrees.

However, I can't figure out how to get it to print correctly. Below is the desired output, my code, and the actual output my code puts out.

Desired Output: Enter three letter name of the triangle:

** Triangle XYZ (angles: X, Y, Z) **

Enter the length a and b:

Enter the angle of X:

Angle X:

Angle Y:

Angle Z: (The letter name of the triangle should take the place of X, Y, and Z in the program, but I can't figure out how to make them all separate values so that they change as the name of the triangle changes.)

My Code:



My Code's Output:

Enter three letter name of the triangle:
**Triangle XYZ (angles: XYZ) ** (The XYZ is one value, not separate like it should be)
Enter the length a and b:

And I haven't gotten past that point.
 
Sheriff
Posts: 17321
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

When in doubt, one of the first places you should look is the Java API Documentation*, commonly called "the JavaDocs," for the version of Java that you're using. Since you're dealing with a String, you'll want to look through the JavaDocs for java.lang.String and see what methods it has that might be useful. There are two, in particular, that you might want to try using: charAt() and toCharArray(). But there are many ways to skin this cat and there are at least two more methods in String that you can leverage to get what you want. Read the documentation, understand what the methods do, and then experiment with them.

I suggest using JShell, the Java REPL to experiment with different String methods.

*links to the Java 11 JavaDocs
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic