Apex Basic Program For Practice
Apex Basic Program For Practice
class FibonacciExample1{
public static void Febo()
{
int n1=0,n2=1,n3,i,count=10;
System.debug(n1+" "+n2);//printing 0 and 1
}}
***ReverseNumber***
***Hello World***
class Simple{
public static void main(){
System.debug("Hello World");
}
}
Pattern program
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
public class pattern
{
public static void main()
{ int i ,j;
int n = 5;
for(i = n; i>0 ; i-- )
{
for(j = 1; j<=i ; j++)
{
System.debug(j);
}
System.debug("");
}
}
*****A
B B
C C C
D D D D
E E E E E
class pattern
{
public static void main5()
{
int n = 4;
for(int i = 0 ; i <= n ; i++)
{
for(int j = 0 ; j <= i ; j++)
{
System.debug(" "+(char)(65 + i));
}
System.debug("");
}
}
}
********
*******
******
*****
****
***
**
*
*******
1
2 3
4 5 6
7 8 9 10
class pattern
$$$$$$$$
//Initialize array
int [] arr = new int [] {25, 11, 7, 75, 56};
//Initialize max with first element of array.
int max = arr[0];
//Loop through the array
for (int i = 0; i < arr.length; i++) {
//Compare elements of array with max
if(arr[i] > max)
max = arr[i];
}
System.debug("Largest element present in given array: " + max);
}
//Declare a string
String str = "This is a really simple sentence";
//Iterate through the string from last and add each character to variable
reversedStr
for(int i = string.length()-1; i >= 0; i--){
reversedStr = reversedStr + string.charAt(i);
}
//Iterate the string forward and backward, compare one character at a time
//till middle of the string is reached
for(int i = 0; i < string.length()/2; i++){
if(string.charAt(i) != string.charAt(string.length()-i-1)){
flag = false;
break;
}
}
if(flag)
System.debug("Given string is palindrome");
else
System.debug("Given string is not a palindrome");
}
}