This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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: 14758
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • 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
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!