Converting characters

I want to convert a character in this program but it won't let me. I don't understand because it lets me do it in another similar program. I tried to change it around as much as possible to get it like the other program to try and nail the problem but I can't do it.
public class Square
private int height = 0;
private int width = 0;
private int surfaceArea = 0;
public void computeSurfaceArea() throws Exception
  char aChar;
  System.out.print("Enter the height ");
  aChar = (char)System.in.read();
  System.in.read();  System.in.read();
  height = Integer.parseInt(aChar);
  System.out.print("the height is  " + height);
  System.out.print("Enter the width ");
  aChar = (char)System.in.read();
  System.in.read();  System.in.read();
  width = Integer.parseInt(aChar);
  System.out.print("the width is  " + width);
  surfaceArea = height * width;
  System.out.print("The area is " + surfaceArea + "\n");
}

Try the following:
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class Square {
     private int height = 0;
     private int width = 0;
     private int surfaceArea = 0;
     public void computeSurfaceArea() throws NumberFormatException, IOException {
          LineNumberReader r = new LineNumberReader(new InputStreamReader(System.in));
          System.out.print("Enter the height: ");
          System.out.flush();
          height = Integer.parseInt(r.readLine());
          System.out.println("the height is  " + height);
          System.out.print("Enter the width: ");
          System.out.flush();
          width = Integer.parseInt(r.readLine());
          System.out.println("The width is  " + width);
          surfaceArea = height * width;
          System.out.println("The area is " + surfaceArea + "\n");
     public static final void main(String[] args) throws Exception {
          new Square().computeSurfaceArea();
}

Similar Messages

  • Converting characters to binary

    Could anyone give me an idea how to convert characters to binary, and vice verse?
    It's like those hex and binary editors out there.

    See if this helps you out
    char c = 'a';
    String binaryString = Integer.toBinaryString(c);
    char translatedChar =
    (char)Integer.parseInt(binaryString, 2);
    System.out.println(binaryString);
    System.out.println(translatedChar);
    Thanks. It worked.

  • How to convert characters in output

    Hello
    I try to write output that automatically converts special characters in simpler versions. Like � to n, � to e, etc.
    I use the structure:
    FileOutputStream fo = new FileOutputStream("output.txt");
    OutputStreamWriter ow = new OutputStreamWriter(fo,"character-encoding");
    ow.write(String,0, String-length);
    But, I do not find a character set that converts the characters in what I want. Instead, all unknown characters come out as ?
    I tried it with ISO8859-1, ISO-8859-15, US-ASCII, ASCII, Cp1252, Cp500 ...
    Is it possible at all what I try or is any unknown character always converted in a question mark?
    Regards, Jan

    Is it possible at all what I try
    Only if you replace the characters yourself. There is no relation between the characters ñ and n, or é and e, apart from the typography. No general way to "remove" the accent/diacretical mark/umlaut/whatever exists.
    or is any unknown character always
    converted in a question mark?That seems to be the case with character encodings in Java.

  • Is it possible to convert characters to movieclip symbols?

    I want to do something like when ppl type in some texts, the
    program will convert every character of the text to a movieclip
    symbol, so I can animate individual characters. Is there a way to
    do something like that?
    Thx in advance~

    yes, you can create (in the authoring or with a.s.) a
    movieclip that contains a textfield and you can assign a linkage id
    to the textfield.
    you can then use the flash string methods to assign each
    letter to its own movieclip/textfield (that you created in the
    first paragraph) using attachMovie(). position your letters and
    animate or animate the movieclip in the first paragraph in the
    authoring environment by putting that movieclip into a timeline and
    use a frame based animation. remove the linkage id on the
    non-animated movieclip with a textfield and assign a linkage id to
    the animated movieclip (that contains your movieclip that contains
    your textfield).

  • Dimension Build Rule converting characters to ascii

    Hi
    I have a dimension build rule which has been in place over a year. However every few weeks it converts some of the dimension members to ascii characters but loads with the correct alias. The next time the load runs, it tries to enter the real member and it falls over as the alias is not assigned to the member with the ascii characters.
    Has anyone seen this before or have any suggestions as to what could be causing it.
    Thanks

    Have you tried recreating the load rule to see if it's some form of weird corruption?
    That doesn't seem very likely (it's either corrupt or it's not <--This is why I Like Computers) -- how about can you confirm that your source is exactly the same both times? I'll bet it's not and you just see the result manifested in the dimension build.
    Regards,
    Cameron Lackpour

  • Need help with converting characters to ASCII code

    Hey. Im trying to write a program to make Caesar Ciphers by random numbers. This cipher must also wrap from front to end of ASCII code, so that if, for example, the character being ciphered is Z and its being modified by +3, the result ciphered character is not "]", but "c".
    Im planning on reading the text that the user inputs (using ConsoleIO) into a string and then seperating each character into a character[]. Then, i would like to find the ASCII code of each character and print out the ASCII code character of the old ASCII code + the modifier.
    So far, this is what i have (sorry for the length, i like to space things out so that its easier on the eyes and more organized... X-( ... ):
    public class EvanFinalB {
         static ConsoleIO kbd = new ConsoleIO();
         static String enteredPhrase;
         static int phraseLength;
         public static void main(String[] args)
              System.out.println("Enter a phrase and this program will cipher it into a secret message.");
              System.out.println("/nEnter your phrase here:");
              //read phrase
              enteredPhrase = kbd.toString();
              //find length of entered text
              phraseLength = enteredPhrase.length();
              //declare arrays for the individual characters of the entered text and the ciphered characters
              char[] enteredChar = new char[phraseLength + 1];
              char[] cipheredChar = new char[phraseLength + 1];
              //loop converting of entered text into seperate characters
              for(int x = 1; x <= phraseLength; x++)
                   enteredChar[x] = enteredPhrase.charAt(x);
                   cipheredChar[x] = cipher(enteredChar[x]);//call cipher() method to find new ciphered character
         //wrap from front to end of ASCII code
         static char cipher(char enteredChar)
              //choose random number to cipher message by
              int modifier = (int)(Math.random() * 26) + 1;
              if(enteredChar + modifier > 90)//90 is the ASCII code for "Z" which is the last capital letter
                   cipheredChar = (97 + (modifier - (90 - enteredChar)));//97 is the ASCII code for "a" which is the first lower case letter
              return cipheredChar[1];
    }The program is obviously in its early stages but (i started creating it today actually), if there is a simple method or anything that i can use to find the ASCII value of a character in order to use enteredChar so that 'enteredChar' is equal to the ASCII code of the new ciphered character, please help me out...Thanks
    P.S. If there's an easier way to go about creating a program for Caesar Ciphers, let me know.

    The following code is from my Java textbook Big Java by Cay Horstmann. It is not my code and it's just to guide you in your own cipher.
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;
       This class encrypts files using the Caesar cipher.
       For decryption, use an encryptor whose key is the
       negative of the encryption key.
    public class CaesarCipher
          Constructs a cipher object with a given key.
          @param aKey the encryption key
       public CaesarCipher(int aKey)
          key = aKey;
          Encrypts the contents of a stream.
          @param in the input stream
          @param out the output stream
       public void encryptStream(InputStream in, OutputStream out)
             throws IOException
          boolean done = false;
          while (!done)
             int next = in.read();
             if (next == -1) done = true;
             else
                byte b = (byte) next;
                byte c = encrypt(b);
                out.write(c);
          Encrypts a byte.
          @param b the byte to encrypt
          @return the encrypted byte
       public byte encrypt(byte b)
          return (byte) (b + key);
       private int key;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Scanner;
       This program encrypts a file, using the Caesar cipher.
    public class CaesarEncryptor
       public static void main(String[] args)
          Scanner in = new Scanner(System.in);
          try
             System.out.print("Input file: ");
             String inFile = in.next();
             System.out.print("Output file: ");
             String outFile = in.next();
             System.out.print("Encryption key: ");
             int key = in.nextInt();
             InputStream inStream = new FileInputStream(inFile);
             OutputStream outStream = new FileOutputStream(outFile);
             CaesarCipher cipher = new CaesarCipher(key);
             cipher.encryptStream(inStream, outStream);
             inStream.close();
             outStream.close();
          catch (IOException exception)
             System.out.println("Error processing file: " + exception);
    }

  • How can I convert characters into ascii code numbers ??

    Read the characters or String from keyboard input then I want the sum of the ascii code of the String or the characters. Please help ....
    Han

    Read the characters or String from keyboard input
    put then I want the sum of the ascii code of the
    String or the characters. Please help ....
    HanThe keyboard input part is a little more coding envolved. Here is a sample of what can be done if
    you know what to implement. It needs three classes
    from the java.io package. Well, here is the complete
    source code for the 'keyboard input' and a driver
    class to test it.
    //package consoleclass;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    class Driver
         public static void main ( String[] args)
              System.out.println("Enter a number");
              int number = MyInput.readInt();
              System.out.println("number entered "+ number);
              System.out.println("Enter another number");
              number = MyInput.readInt();
              System.out.println("number entered "+ number);
    class MyInput
      /**Read a string from the keyboard*/
      public static String readString()
         BufferedReader br
           = new BufferedReader(new InputStreamReader(System.in), 1);
         // Declare and initialize the string
         String string = " ";
         // Get the string from the keyboard
         try
           string = br.readLine();
         catch (IOException ex)
           System.out.println(ex);
         // Return the string obtained from the keyboard
         return string;
      /**Read an int value from the keyboard*/
      public static int readInt()
         return Integer.parseInt(readString());
      /**Read a double value from the keyboard*/
      public static double readDouble()
         return Double.parseDouble(readString());
    }

  • Converting ASCII characters to integer values

    I'm trying to convert characters to ints in order to see if they are within the ASCII encoding set. Having trouble finding a method to do this.

    This is simple in java you can just cast a char to an
    int.
    For example, a method to print the ascii value of a
    char:
    public void printAscii(char c) {
    int asciiValue = (int) c;
    System.out.println(asciiValue);
    }Actually a cast is not necessary as a char is automatically cast to an int by Java. -
    int asciiValue = c; is fine and works correctly.
    Also, as DrClap said - and less than 127.

  • Problems with german characters in data migration

    Hello,
    I tried to migrate a Access 2002 mdb to Oracle 10g XE. In order to avoid errors I used Access 2000 exporter to generate xml and dat for table and data, imported the schema to Oracle database, generated data move scripts and imported the data with a batch-file.
    I did it according to the steps explained here:
    http://www.oracle.com/technology/tech/migration/workbench/viewlets/ofdm.html
    http://www.oracle.com/technology/obe/11gr1_db/appdev/msamigrate/msamigrate.htm
    All german characters in Table names were migrated correctly. But when I import the data, german characters are converted to weird signs like ü.
    If I open the dat-files with windows editor all german characters are displayed properly. If I open the same file with wordpad the german characters are displayed with the errors described above.
    Environment
    Win XP SP 3 German
    Ms Access 2002 sp3 german
    SQL Developer 1.5.0.53 german
    Access 2000 Exporter 10.2.0.2.5
    What am I doing wrong? I can't get it solved since two days.

    Check if database characterset supports these special characters
    check client's nls settings.
    check client machine's language settings (converts characters in driver level)

  • Problems with special characters in the data.

    Hi All,
    Whenever, I'm trying to data such as "Lämmerzunge" which are having some special characters in it, it is storing them as L�mmerzunge. Is there anyway to handle these?
    Thanks in advance.
    Regards,
    Venky

    Check if database characterset supports these special characters
    check client's nls settings.
    check client machine's language settings (converts characters in driver level)

  • Convert a string to its unicode representation

    how can I convert characters such as "ащщ"
    to their unicode numbers (1072,1097,1097)? I know it's gotta be so
    easy, but it's going over my head.

    ogre11 wrote:
    > when I give any Cyrillic character to a cf function it
    gets converted into a
    > question mark at some point before the function runs so
    asc returns 63 on all
    > cyrillic characters
    encoding issue. where's the data coming from? if db, which
    one? what driver? is
    the data really unicode?
    do you have a simple example showing the problem?

  • Mac: Problems with certain characters in the editor

    I have now downloaded the production version on my Mac and it runs just fine. The first thing I see is that the painting problems with the close icons etc. have been fixed. Thank you for that. But I still have trouble typing certain characters in the editor. I haven't reported that yet, but I have seen others report similar problems caused by missing support for international keyboards. The characters that I cannot type are |\[{]} which is pretty annoying when you're writing Java code. :-) It works fine in normal Java text fields. On my Norwegian keyboard I normally input all these characters by typing 7 and 8 combined with option or option + shift.

    Check if database characterset supports these special characters
    check client's nls settings.
    check client machine's language settings (converts characters in driver level)

  • Issue: Characters / encode /decode & Solution

    Hey guys,
    Few issues on this, I think we will need an encode/decode filter.
    I guess this is related to how if you read a cookie in liquid it converts characters like a comma into its entity (This isn not fixed yet).
    Example:
    <meta property="og:description" content="{{description | strip_html | truncate:200,'...' }}">
    The resulting markup is:
    <meta property="og:description" content="Seven advisers within National Australia Bank's (NAB) salaried advice business, NAB Financial Planning (NAB FP), have transitioned to the bank&rsquo;s newly-launched self-employed model.
    As first ...">
    You can see it has stripped out the html markup but has encoded a ' with it's entity. I can see in some cases this is good but in other cases this is bad. You can also see that <br/> while stripped are treated as new lines instead.
    Liquid itself for these reasons have:
    escape - escape a string
    escape_once - returns an escaped version of html without affecting existing escaped entities
    strip_html - strip html from string
    strip_newlines - strip all newlines (\n) from string
    newline_to_br - replace each newline (\n) with html break
    You only have strip_html but not the other filters. I think if you implemented these then we can address these issues.

    Hi Liam,
    The encoding problem cannot be reproduced. Even in your example, some of the quotes are outputted correctly while a single one not. Can you edit the source of the content and try to re-enter the character from the editor, just to eliminate a possible copy / paste issue from word with a weird character encoding?
    On the new line issue, it seems to happen on some scenarios. For example:
    {{" <div>Seven advisers within National Australia Bank's (NAB) salaried advice business, NAB Financial Planning (NAB FP), have transitioned to the bank's newly-launched's self-employed <br /> model. at first's</div>" | strip_html }} - does not reproduce the problem
    <meta property="og:description" content="{{" <div>Seven advisers within National Australia Bank's (NAB) salaried advice business, NAB Financial Planning (NAB FP), have transitioned to the bank's newly-launched's self-employed <br /> model. at first's</div>" | strip_html }}”> - does reproduce the problem
    Cristinel

  • Ho to convert to lower case values and upper case

    hi
    pls let me know how to convert the varlues to lower case
    and how to conver values to uppoer case
    whichis funtion module to do so?
    regards
    Arora

    Hi,
    <b>TRANSLATE</b>
    Converts characters to strings.
    Syntax
    TRANSLATE <c>  TO UPPER|LOWER CASE
                  |USING <r>.
    The characters of the string <c> are converted into upper- or lowercase, or according to a substitution rule specified in <r>.

  • Any way to map characters to sequences of virtual key codes?

    I have a text and I need to make the java.awt.Robot class instance to type it. The text may contain any Unicode characters. Unfortunately the Robot class accepts only virtual key codes which generate different characters depending on the currently used keyboard layout. I was wondering whether there is any way to create a map of how to convert Unicode characters onto combinations of keyboard layout(s) and sequences of KeyEvent virtual key codes?
    I was originally hoping to find access to the method which interprets sequences of virtual keys (represented by KeyEvent instances of type KEY_PRESSED and KEY_RELEASED) and generates a KEY_TYPED key event (which already contains the resulting character). I however failed to find the code responsible for this functionality and I'm afraid this is done by the underlying operating system. Can anyone give me a hint on where to search?
    The only workable solution I've found so far is to fire sequences of KEY_PRESS and KEY_RELEASED events and their combinations with the Shift key, listen for eventual KEY_TYPED events and save the mapping between the original press/release sequence and the resulting character if such an event is received. This can be repeated for a set of keyboard layouts switched through InputContext.selectInputMethod().
    This solution is however an ugly, inefficient and time consuming hack which may or may not find mapping for a particular character. It also requires a GUI displayed so that one can receive key events, and I also need to find a solution which would run without GUI just from CLI.
    Does anyone have an idea on how to implement this more efficiently?

    I suspect that you are trying to solve the wrong problem. I don't see any reason for converting characters to virtual keys because:
    * this is dependent of current keyboard layout
    * many characters will not map at all
    If you want to use shortcuts use the virtual key codes instead. I wrote few articles regarding keyboard usage in an international context - check http://blog.i18n.ro/category/readiness/input/

Maybe you are looking for

  • Can no longer connect to my wireless due to accidental bluetooth change.

    i recently bought my macbook and the wireless was working fine on it. Until i tried to pair my phone to it using bluetooth. The setting then changed to bluetooth PAN. network diagnostics then said airport was connected to a personal IP adress and wou

  • IPod/iTunes Sound Volume problems

    I listen to my iPod Mini on my car radio, and used to enjoy turning the music up loud sometimes. Now I cannot GET it loud, even though I have the volume on my radio and iPod set to the maximum. For audiobooks, I can no longer hear the words clearly o

  • Freight and insurance cost in PO

    Hi In the PO line item the costs for freight, insurance are specified to capture the cost into the material cost.Moreover they want to create contracts for freight and insurance.When creating the material PO they want to link the contract for the fre

  • Help in removing Space & Character

    Hi, I have a query where I need to remove the space & the character after this space in the query. Here is the query and the sample data. I am using Oracle 11g db select replace(my_col, chr(10), chr(32))test from tableA; ID       TEST 1        121 1 

  • Preventing iPhoto Library being a bundle

    A question to the advanced power users: Does anybody know how to prevent the iPhoto Library turning from a folder into a bundle each time after iPhoto has been used? In other words: I want to keep the iPhoto Library as a plain folder. As of now, afte