Blogs

program to find whether the number is armstrong or not

simple java program to display armstrong number. What is armstrong number - In armstrong number sum of cubes of its digits is equal to the number itself.
Example 1: 153 - 1^3+5^ 3+ 3^ 3 =1+125+27= 153, therefore 153 is armstrong number.
Example 2: 125 - 1^ 3+2^ 3+5^ 3= 1+8+125=134, therefore 125 is not an armstrong number.

The code check  the number given by user is amrstrong number or not .

 

Program to reverse digits in a number

Simple java program to reverse the digits in a number. Logic for reversing the number, sum of digits and armstrong number are similar, even in c sharp, php, c++, c.  To reverse, digits are manipulated from last position. Solution and explanation, for the program is below.

 

class RevNumber
{
public static void main(String args[])
{
int s=0,x,n=425;
while(n > 0)
{
x=n%10;
s=s*10+x;
n=n/10;
}
System.out.println(“ The Reversed number is :”+ s);
}
}

 

fetch data from database using php/mysqli select query

fetch data from mysql table and print using php. Here data are displayed in tabular format (multiple column), but it can be changed to noraml display.  Let us see, how mysql select query retrieve and print data via php.

Very simple php code. Change the DB name and password. Connection details can also be made in different php.

<?php

$DBServer = 'localhost'; // e.g 'localhost' or '192.168.1.100'
$DBUser   = 'root';
$DBPass   = '';
$DBName   = '';

$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName);

Connect database using php/mysqli

1st php mysql application using database connection. Let us see how to connect mysql database using php5.This topic covers creating a database in mysql, code or program to establish connection, print the message.
Mysqli is a relation database driver used as an interface between mysql and php .
mysqli is a replacement for the mysql fuctions, with object oriented and procedural version. If you are beginner proceed with mysqli.

Sum of elements of array program

simple java program to sum all the numbers in an integer array. Build-in function to sum a values in array is used in java8. array_sum in php.

class Sumarray{
    public static void main(String args[])  {
int[] a={8,5,6,2,4};
int sum=0;
for(int i=0;i<  a.length;i++)
{
sum +=a[i];
}
System.out.println(“Sum of array”+sum);
}}

 

output:
Sum of array 25

Reverse the elements in array

Simple java program to reverse content in array. Logic is easy, it can also be used in other programming languages such as c# sharp, php... Here the index is reversed so the elements in the array are reversed.

class Reversearray{
    public static void main(String args[])  {
  int[]  oldarray={4,5,6};
  int[] resultarray=new int[3];
int m=0;
int len=oldarray.length;
for(int i=len-1;i>=0;i--)
{
resultarray[m]=oldarray[i];
m++;
}
for(int i=0;i<  oldarray.length;i++)
{
System.out.println(resultarray[i]);
}
}
}

 

output:

Pages