Pythagors into java-code (i got the idea, i think,  but need it simplified)

Goodday all :),
I have been trying to turn the forumula | a^2 + b^2 = c^2 | into java code.
To clear it up a little more;
1. Define unknown variable
2. Define values of other two variables
3. Program calculates
x1. unkown variable is 'a'
x2. b = 20 , c = 40
x3. a = [(40^2) - (20^2)] ^0.5 (sorry couldnt figure out superscript)
What i was thinking as a concept;
1. Java asks for uknown value -> user defines as 'a' , 'b' or 'c'.
2. Java If else statement
2.1 if 'd' -> java asks again
2.2 else 'e' --> java asks again etc (if else statemenst from d - z)
import java.io.*;
public class example {
     public static void main(String[] args) {
          System.out.println("define uknown value");
          BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
          boolean running = true;
          while(running) {
                    String line = reader.readLine();
                    if (line.startsWith("d")) {
                         System.out.println("wrong input, define unknown value");
                         running = true;
                         } else      if (line.startsWith("e")) {
                         System.out.println("wrong input, define unknown value");
                         running = true;
                         } else      if (line.startsWith("f")) {
                         System.out.println("wrong input, define unknown value");
                         running = true;
                         } else      if (line.startsWith("g")) {
                         System.out.println("wrong input, define unknown value");
                         running = true;and furter i was thinking;
If a, b or c is pressed it will ask for the values of the other two
and it will be such a code as above, repeating itself;
                    String line = reader.readLine();
                    if (line.startsWith("a")) {
                         System.out.println("please define b");
                         running = true;
                         if (line.startsWith("1")) {
                         int x = 1;
                         System.out.println("b=1");
                         running = true;
                         } else      if (line.startsWith("2")) {
                         int x = 2;
                         System.out.println("b=2");
                         running = true;
                         } else      if (line.startsWith("3")) {
                         int x = 3;
                         System.out.println("b=3");
                         running = true;and so on till, lets say 1000?
Now my question is;
Is this the right way to make this program?
I would have like a .java file of severel megebytes if i wanted the values to get up to 10000 or something >.<

Aargh! No. This code snippet might be of help.
try {
   int x = Integer.parseInt("42");
   System.out.println("X = " + x);
} catch( NumberFormatException e ) {
   System.err.println("Not a number: " + e);
   e.printStackTrace();
}You would probably also find it useful to read about "regular expressions" if you always expect the formula to have exactly the same form.

Similar Messages

  • After upgrading to IOS 7 on my iPhone 4 and iTunes 11 on my PC, I plugged my iPhone into my PC and got the error message that I needed to install iTunes 11 on my iPhone. Any suggestions?

    After upgrading to IOS 7 on my iPhone 4 and iTunes 11 on my PC, I plugged my iPhone into my PC and got the error message that I needed to install iTunes 11 on my iPhone. Any suggestions?

    You got it downloaded and I assume you mean it is installed as well.  It was buggy for me.
    I had to close and restarted iTunes before I could use it properly.
    Then, I had to unplug and replug in my phone before it recognises it.
    Just had to try everything.  As final choice, update over the air.  I try to avoid it as it tends to have more problems than a tethered update.

  • How to transform this pascal code into java code!

    I want to transform this pascal code into java code . Please tel me how to do it because I really don't know how to do it!
    Thanks!
    {CALCULATE HOHN-LONDON FACTORS}
    var kk:tab4;
    PROCEDURE INTENS(var kk:tab4);
    begin
    for n:=0 to nr+2 do
    begin
    kk^[1,n]:=sqrt(lup*lup*yg*(yg-4)+4*sqr(n+1)) +lup*(yg-2);
    kk^[2,n]:= sqrt(lup*lup*yg*(yg-4)+4*sqr(n+1))-lup*(yg-2);
    kk^[3,n]:=0.5*(kk^[1,n]*kk^[1,n]+4*(sqr(n+1)-lup*lup));
    kk^[4,n]:= 0.5*(kk^[2,n]*kk^[2,n]+4*(sqr(n+1)-lup*lup));
    kk^[5,n]:= sqrt(ldown*ldown*yd*(yd-4)+4*sqr(n+1)) +ldown*(yd-2);
    end;
    end;
    BEGIN
    new (kk);
    intens(kk);
    writeln(f2,' ','N ','V','branch ','H-L');
    for n:=1 to np do
    begin
    fp1[n,v]:=(n-ldown)*(n+ldown+1)*sqr(kk^[2,n-1]*kk^[6,n]+4*(n+ldown)*(n-ldown+1));
    fp1[n,v]:=fp1[n,v]/(4*(n+0.5)*kk^[4,n-1]*kk^[8,n]) ;
    writeln(f2,' ',n,' ',v,' fp1 ',fp1[n,v]:10:2);
    end;
    for n:=1 to nq do
    begin
    fq1[n,v]:=sqr(kk^[2,n]*kk^[6,n]*(ldown+0.5)+4*(n-ldown+1)*(n+ldown+1)*(ldown-0.5)) ;
    fq1[n,v]:=fq1[n,v]/(2*(n+0.5)*kk^[4,n]*kk^[8,n]*(n+1.5));
    fq1[n,v]:=fq1[n,v]*(n+1);
    writeln(f2,' ',n,' ',v,' fq1 ',fq1[n,v]:10:2);
    end;
    for n:=1 to nr do
    begin
    fr1[n,v]:=sqr(kk^[2,n+1]*kk^[6,n]+4*(n-ldown+2)*(n+ldown+1));
    fr1[n,v]:=fr1[n,v]/(4*kk^[4,n+1]*kk^[8,n]*(n+1.5));
    fr1[n,v]:=fr1[n,v]*(n-ldown+1)*(n+ldown+2) ;
    writeln(f2,' ',n,' ',v,' fr1 ',fr1[n,v]:10:2);
    end;

    Basically it looks like this:
    public class KK{
         private your_type[][] kk = new your_type[length][length];
         private void intens(your_type[] kk){
              for(int n= 0; n<nr+2; n++){
                   kk[1][n] = Math.sqrt(lup*lup*yg*(yg-4)+4*Math.pow((n+1), 2)) +lup*(yg-2);
                   kk[2][n] = Math.sqrt(lup*lup*yg*(yg-4)+4*Math.pow((n+1), 2))-lup*(yg-2);
                   kk[3][n] = 0.5*(kk[1][n]*kk[1][n]+4*(Math.pow((n+1), 2)-lup*lup));
                   kk[4][n] = 0.5*(kk[2][n]*kk[2][n]+4*(Math.pow((n+1), 2)-lup*lup));
                   kk[5][n] = Math.sqrt(ldown*ldown*yd*(yd-4)+4*Math.pow((n+1), 2)) +ldown*(yd-2);
         public static void main(String args[]){
              KK k = new KK();
              k.intens(kk);
              System.out.println(f2  + ' ' + 'N ' + 'V' + 'branch ' + 'H-L');
              for(int n=1; n < np; n++){
                   fp1[n][v] = (n-ldown)*(n+ldown+1)*Math.pow((kk[2][n-1]*kk[6][n]+4*(n+ldown)*(n-ldown+1)), 2);
                   fp1[n][v] = fp1[n][v]/(4*(n+0.5)*kk[4][n-1]*kk[8][n]) ;
                   System.out.println(f2 + ' ' + n + ' ' + v + ' fp1 ' + fp1[n][v]:10:2);
              for(int n=1; n< nq;n++){
                   fq1[n][v] = Math.pow((kk[2][n]*kk[6][n]*(ldown+0.5)+4*(n-ldown+1)*(n+ldown+1)*(ldown-0.5)), 2);
                   fq1[n][v] = fq1[n][v]/(2*(n+0.5)*kk[4][n]*kk[8][n]*(n+1.5));
                   fq1[n][v] = fq1[n][v]*(n+1);
                   System.out.println(f2 + ' ' + n + ' ' + v + ' fq1 ' + fq1[n][v]:10:2);
              for(int n=1; n < nr; n++){
                   fr1[n][v] = Math.pow((kk[2][n+1]*kk[6][n]+4*(n-ldown+2)*(n+ldown+1)), 2);
                   fr1[n][v] = fr1[n][v]/(4*kk[4][n+1]*kk[8][n]*(n+1.5));
                   fr1[n][v] = fr1[n][v]*(n-ldown+1)*(n+ldown+2) ;
                   System.out.println(f2 + ' ' + n + ' ' + v + ' fr1 ' + fr1[n][v]:10:2); //fr1[n][v]:10:2 --> Here you must use the BigDecimal class
    }I'm not very sure because my pascal knowledge is extremely "dated".
    What about the converter I told you about?

  • "embed" image data into java code

    I have a mind that is it possible embed image file into java code?
    That mean an image file information already store in java code, thus no need using the image file in run-time. Then can prevent user change other image file instead.
    Do anyone try before, are there technologies required?
    I just want to know is it possible or not....thanks.

    technologies? The solution you are asking for is all about storing your data in static variables such as byte[][] used to build your image instance. I guess you should have a look at the different constructors of BufferedImage.

  • Update the result to client (JAVA code) aftere completing the user task

    Hi All,
    I have a simple workflow activity with in my BPEL process .
    FLOW is like this:
    1)----->Initiate/Process
    2)----->Workflow user task
    3)Approve/Reject /Others
    4)If APPROVE a call to web-service method
    5)reply
    If i got the out put as approve the next step is a call to web-service which should give the output to client(JAVA code).
    Is the above senario possible through BPEL.
    Thanks,
    Kalyan.

    HI ALL
    I fixed this problem. Problem was because of classpath. After setting the path of class file in classpath, issue was fixed.
    Regards
    Arun

  • Static initialization of java code included in the Imported Archives jars?

    Hi
    Does SAP PI 7.0 support static initialization of java code included in the Imported Archives jars?
    Static block of a java class included in the Imported Archive jars throws a Runtime Exception called ExceptionInInitializationError while trying to run.
    Regards,
    RDS

    Have you tested the code outside PI?

  • How to write java code to read the pixel color in some place of screen?

    Hello all:
    How to write java code to read the pixel color in some place of screen?
    The java application iteself doesn't have any GUI.
    thank you
    -Danel

    See java.awt.Robot

  • TS3297 I tried to download with a redemption code and got the message: "your computer isn't authorized"

    I tried to download with a redemption code and got the message: "your computer isn't authorized" -- how do I do that?

    Quit Safari, launch it directly from HD/Applications/ instead; trash the old version 5.1 on your Desktop... it isn't working with the Safari 5.1.1 system frameworks, and wasn't updated due to not being in HD/Applications/

  • How do I pass an error status from my java code back to the Program Job Ser

    How do I pass an error status from my java code back to the Program Job Server?
    I have a jar program object that reports a scheduled status of "Success" even if the java code errors out.

    Exceptions thrown from the program object are ignored by the program job server.
    You need to configure the Program Object, then stream out a special string sequence to the stdout of the Program Object, to set the scheduled instance status to Failed.
    Look up SAP KBase  1201804 - How to programmatically set the status of a Program object to "Failed"
    Sincerely,
    Ted Ueda

  • I just got my new laptop tonight and got the free lion download but once i tried to install it is said the download was corrupted?? what do i do??

    i just got my new laptop tonight and got the free lion download but once i tried to install it is said the download was corrupted?? what do i do??

    Go into your Applications folder
    Find the app named Install Mac OS X Lion.app
    Move that app to the trash
    relaunch The App Store
    go to your Purchased list
    Click on install next to Lion
    It will re-download the installer

  • I just got the ios 8 update but now my ipod 5 wont turn on

         I just got the IOS 8 update but now my ipod 5 wont turn on.

    If it has NEVER been jailbroke, here are some standard repair procedures:
    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  It could take well over an hour!  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow the on-screen directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore (or it doesn't help), go into Recovery Mode per the instructions here.  You WILL lose all of your data (game scores, etc,) but, for the most part, you can redownload apps and music without being charged again.  Also, read this.

  • How do i connect my macbook pro to another screen (a fujitsu siemens) i got the cable for it but i want to know the settings so i transfer desc to the fujitsu screen.

    How do i connect my macbook pro to another screen (a fujitsu siemens) i got the cable for it but i want to know the settings so i transfer desc to the fujitsu screen.

    Welcome to Apple Support Communities
    If you have the cable, just connect it to both and the desktop will show up on the external display. Then, you can select different modes, changing arrangement in System Preferences > Displays > Arrangement, or using shortcuts > http://support.apple.com/kb/ht5019

  • When i turn my iphone 4 on, it comes up with a picture of a cord connecting to an itunes icon. when i plug it into my pc, it says the settings on my iphone need to be restored. but i dont want to restore it as will lose everything on it. what shall i do?

    when i turn my iphone 4 on, it comes up with a picture of a cord connecting to an itunes icon. when i plug it into my pc, it says the settings on my iphone need to be restored. but i dont want to restore it as will lose everything on it. what shall i do?

    You have no chose but to restore your phone. What do you mean "lose everything"? Is your data/iTunes content not on your computer?

  • I've been using samsung for a long time and I just changed into an iPhone 5s and the most important thing I need is my calendar appointments , but in the notification center it doesn't show my events for tomorrow , will there be an updated or this soon?

    I've been using samsung for a long time and I just changed into an iPhone 5s and the most important thing I need is my calendar appointments , but in the notification center it doesn't show my events for tomorrow and it doesn't even show more than 1 event  , will there be an updated or this soon? Or should I just shift back to samsung?????

    Go to settings/notification centre and make sure today vie and calendar day view are both on

  • Tried numerous times to create account, got the email to verify but the link to verify is missing, how do i verify my email address ?

    Tried numerous times to create account, got the email to verify but the link to verify is missing, how do i verify my email address ?

    Hi,
    Might be something in Here to Help:
    Apple ID FAQ
    http://support.apple.com/kb/HE37http://support.apple.com/kb/HE37
    How do I verify my Apple ID by email?
    Simply follow the link in the verification email that says "Verify Now." Sign in with your current Apple ID and password, then click Verify Address.
    You can also verify by signing in at My Apple ID.

Maybe you are looking for

  • HT203254 crack in the MacBook Pro display

    Would a crack in the MacBook Pro display cause a similar "fade-to-white" symptom as a bad graphics processor?

  • How to use the url in the work item

    hi ,guys ,    I have question in design the workflow, my scenario is as follows : I develop the workflow in the sap gui ,then integrate it into the portal using uwl . now i want add a link in the work item ,before approver excute the work item ,the a

  • Animating .gif on .gif background

    hi, i am making a little fish game where you can click directional buttons to move fish .gifs around a fish tank. i am trying to display .gif pictures of fish on top of my background, im struggling with paint and update and layeredpanes and whether t

  • Insert numbers table into pages v5.2.2

    I seem to remember being able to copy and paste tables from numbers to pages. Now I have a new computer and cannot do this. Any hints?

  • Is there a quick way to convert Albums to Projects?

    Due to bringing in legacy organizing from iView MediaPro into Aperture years ago... I have an organizational structure consisting of few top level Projects containing many Albums. I now realize I should have few top level Folders containing many Proj