It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Java based compiler giving me problems

Java based compiler giving me problems

Postby sasukechaos on Wed Nov 15, 2006 11:21 am

For some reson the buffered reader that im using

BufferedReader BR = new BufferedReader(new InputStreamReader (System.in));

isnt liked by "DoctorJava" Can anyone guess why? And in the meantime, is there anything else worng with this?

/*Joe Spike
*2nd period
* Palindrome
*Nov 9,06
*/

import java.io.*;

public class Palindrome
{
public static void main (String args[]) throws IOException
{

String str1, letterA, letterB;
int first, last;
double counter, lenght;

//Setup Buffered Reader
BufferedReader BR = new BufferedReader(new InputStreamReader (System.in));

//inputs
System.out.println("Input a Word. I'll check if its a palindrome, but please remove all the spaces from it if its a sentance ok?");
str1 = BR.readLine();

//Solve common User Error
str1.toLowerCase();

//Set variable values for use in loop
length = str1.length();
first=(-1);
last=length;

//Do loop to run through letters
do {
//incremented
first++;
last--;
//display letters to middle
letterA=(str1.substring(first,1));
letterB=(str1.substring(last,1));

//if statment to add to counter
if (str1.substring(first,1)==str1.substring(last,1)) {
counter++;
}
System.out.println (letterA + " " + letterB);
}
while ((first!=last) || (first<last));

//if all the letters to the middle or one over match and 1 is added to the counter for each that matches with one on the oposite side, then the counter would only be greater if each letter matched - a palindrome)
if (counter>(length/2)) {
System.out.println("Guess what! you gots a palindrome!");
}
sasukechaos
 
Posts: 0
Joined: Wed Nov 15, 2006 11:17 am

Who is online

Users browsing this forum: No registered users and 5 guests