Tuesday, December 23, 2014

Infinite For loop and Java Palindrome Number in java pro



Infinite For loop

public class InfiniteForLoop
      
public static void main(String[] args)
{     
for(;;)
System.out.println("Hello");
  }
}

Java Palindrome Number

public class JavaPalindromeNumberExample
{
public static void main(String[] args)
{
int numbers[] = new int[]{121,13,34,11,22,54};
for(int i=0; i < numbers.length; i++)
{
int number = numbers[i];
int reversedNumber  = 0;
int temp=0;
while(number > 0)
{
temp = number % 10;
number = number / 10;
reversedNumber = reversedNumber * 10 + temp;
}
if(numbers[i] == reversedNumber)
System.out.println(numbers[i] + " is a palindrome number");
else
System.out.println(numbers[i] + " is not a palindrome number");
    }
  }
}

Java Pyramid

public class JavaPyramid1
{
 public static void main(String[] args)
{
 for(int i=1; i<= 5 ;i++)
{
 for(int j=0; j < i; j++)
{
System.out.print("*");
}
System.out.println("");
  }
 }
}

No comments:

Post a Comment