convert java code into PHP. can some one convert this java code to PHP

public class TestClass {


public static void main(String[] args) {

for(int i=0;i<100;i++) {

int j = i-7;

int k = j%10;

if ( k == 0) {

System.out.println("Actual I value reminder by 7 is : " +i);

}

String str = Integer.toString;

if (str.length() > 1) {

if (str.substring(0,1).equals(str.substring(1))) {

System.out.println("BUZZ " +i);

}

}

}

}

}

ukapu2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lukasz ChmielewskiCommented:
I'm not sure what this does though:
String str = Integer.toString;

<?php
class TestClass {

    function main() {
        for($i=0;$i<100;$i++) {
            $j = $i-7;

            $k = $j % 10;

            if ($k == 0){
                echo "Actual I value reminder by 7 is : ".$i;
            }

            //String str = Integer.toString;

            if (str.length() > 1){
                if (substring($str,0,1) == substring($str,1)){
                    echo "BUZZ ".$i;
                }
            }
        }
    }
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lukasz ChmielewskiCommented:
Sorry, strlen should be there.

<?php
class TestClass {

    function main() {
        for($i=0;$i<100;$i++) {
            $j = $i-7;

            $k = $j % 10;

            if ($k == 0){
                echo "Actual I value reminder by 7 is : ".$i;
            }

            //String str = Integer.toString;

            if (strlen($str) > 1){
                if (substring($str,0,1) == substring($str,1)){
                    echo "BUZZ ".$i;
                }
            }
        }
    }
}
?>

Open in new window

0
Slick812Commented:
greetings ukapu2005, I can see no purpose in converting this function to PHP, as it seems to me, , the main function does NOT do anything useful? ? Is this some sort of homework assignment?
although Roads_Roads has given you a translation, In my view Roads_Roads did not get the Integer thing correct, I would use the $i variable as the $str string. Also there is some difference between Console output in PHP (and Java) and web output.

What are you trying to do? ? Why would you need the output of "BUZZ 3". this is always the same every time this is run and there will always be the same double digits (44, 55) in a run of 0 to 99, and Why is there a String[] args in the main function parameters and the args is never accessed or used? ?
class TestClass {

static public function main($args) {
for($i=0;$i<100;$i++) {
	$j = $i-7;
	$k = $j%10;
	if ($k == 0) {
		echo 'Actual I value reminder by 7 is : '.$i;
		// fwrite(STDOUT, 'Actual I value reminder by 7 is : '.$i."\n");
		}
	$str = ''.$i;
	if (strlen($str) > 1) { 
		if (substr($str,0,1) == substr($str,1,1)) echo 'BUZZ '.$i;
		}
	}
}
} // end of class TestClass

TestClass::main(7);

Open in new window

0
SamsonChungCommented:
this looks like home work....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.