I'm not using non allowed function

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
escualo
New poster
Posts: 1
Joined: Wed Oct 23, 2002 4:41 pm

I'm not using non allowed function

Post by escualo » Wed Oct 23, 2002 8:20 pm

[java]

Code: Select all

import java.io.*;
import java.util.*;

class Main
{
	private final char APOSTROFE = (char) 96;
	
	static String ReadLn (int maxLg)  /* utility function to read from stdin */

    {
        byte lin[] = new byte [maxLg];
        int lg = 0, car = -1;
        String line = "";

        try
        {
            while (lg < maxLg)
            {
                car = System.in.read();
                if ((car < 0) || (car == '\n')) break;
                lin [lg++] += car;
            }
        }
        catch (IOException e)
        {
            return (null);
        }

        if ((car < 0) && (lg == 0)) return (null);  /* eof */
        return (new String (lin, 0, lg));
    }

    public static void main (String args[])  throws Exception /* entry point
from OS */
    {
        System.setIn(new FileInputStream("p272.in"));
        Main myWork = new Main();  /* create a dinamic instance */
        myWork.Begin();            /* the true entry point */
    }

    void Begin()
    {
        String input;
        boolean bSw = false;
        while ((input = Main.ReadLn (255)) != null)
        {
          	String sCadena = input;          
			for(int j = 0; j<sCadena.length(); j++) {
				if(sCadena.charAt(j) == '\"') {
					if(!bSw) {	/* Parentesis abierto */
						System.out.print(APOSTROFE);
						System.out.print(APOSTROFE);
						bSw = !bSw;	
					}
					else { /* Parentesis cerrado */
						System.out.print('\'');
						System.out.print('\'');
						bSw = !bSw;
					}
				}
				else
					System.out.print(sCadena.charAt(j));
			}
			System.out.print('\n');
		}
    }
}
[/java][/code]
Aplication's Developer

Spike
New poster
Posts: 29
Joined: Mon Mar 18, 2002 2:00 am
Location: Washington State
Contact:

Ok

Post by Spike » Fri Oct 25, 2002 5:23 am

Try getting rid of the System.setIn()

Post Reply

Return to “Java”