6 Replies Latest reply: Nov 26, 2008 7:02 AM by 800308 RSS

    Reading and printing a unicode character

    843785
      Hey guys, I'm currently working on a tester that will help me for my trigonometry class. I have a file that it's reading from which contains the pi and radical sign characters, but when I use System.out.print it comes out as some weird other characters. I was wondering how I could print out the respective pi and radical characters.
      Thanks!

      Here's the code although I doubt it will help:
      /*
       * Author: DK
       * Creation Date: 11/25/2008
       */
      import java.io.*;
      import java.util.*;
      
      class UnitCircleTester {
          public static void main (String[] args) throws IOException 
          {
              //reads file
              BufferedReader f = new BufferedReader(new FileReader("unitcircle1.in"));
              String[][] arr = new String[32][2];
              for (int i = 0; i < 32; i++)
              {
                  arr[0] = f.readLine();
      f.readLine(); //for some reason reader reads the file with lines in between the lines
      arr[i][1] = f.readLine();
      f.readLine(); //for some reason reader reads the file with lines in between the lines
      }
      arr[0][0] = arr[0][0].substring(2); //weird character


      //picks random questions
      ArrayList<Integer> list = new ArrayList<Integer>();
      for (int i = 0; i < 32; i++)
      {
      list.add(i);
      }
      int[] ind = new int[10];
      for (int i = 0; i < 10; i++)
      {
      ind[i] = list.remove((int)(Math.random() * list.size())).intValue();
      }

      //actual test
      Scanner s = new Scanner(System.in);
      System.out.println("Instructions:");
      System.out.println("Please type any character to start your test.");
      System.out.println("When finished, type any character to stop your test.");
      System.out.println();
      String start = s.next();
      Stopwatch stopwatch = new Stopwatch();
      stopwatch.start();
      for (int i = 0; i < 10; i++)
      {
      System.out.println(i+1 + ". " + arr[ind[i]][0]);
      }
      String stop = s.next();
      stopwatch.stop();
      System.out.println();
      System.out.println("Answers:");
      for (int i = 0; i < 10; i++)
      {
      System.out.println(i+1 + ". " + arr[ind[i]][1]);
      }
      System.out.println("Test time: " + stopwatch.getElapsedTimeSecs() + " seconds");
      System.out.println();
      }
      }
      Edited by: youmefriend722 on Nov 26, 2008 12:47 AM