Tuesday, August 16, 2011

Using JOptionPAne Converter for Decimal To Octal Decimal


import javax.swing.JOptionPane;
 import java.io.*;
 import java.lang.*;
public class DecimalToOctal {
    public static void main(String[] args) {
    String deci;
  deci = JOptionPane.showInputDialog(null, "Enter the decimal number:");
     int w = Integer.parseInt(deci);
  String str = Integer.toString(w,8);
  JOptionPane.showMessageDialog(null, "octal:=" + str,"result", JOptionPane.INFORMATION_MESSAGE);
  System.exit(0);
    }
}

Using JOptionPAne Converter for Decimal To Hexadecimal


import javax.swing.JOptionPane;
 import java.io.*;
 import java.lang.*;
public class DecimalToHexadecimal {
   
    public static void main(String[] args) {
    String hex;
        hex = JOptionPane.showInputDialog(null, "Enter the decimal value:");
        int i = Integer.parseInt(hex);
        String hex1 = Integer.toHexString(i);
       JOptionPane.showMessageDialog(null, "Hexa decimal: " + hex1,"Result", JOptionPane.INFORMATION_MESSAGE);
       System.exit(0);
    }
}

Using JOptionPAne Converter for Binary To Hexadecimal


import javax.swing.JOptionPane;
 import java.io.*;
 import java.lang.*;
public class BinaryToHexadecimal {
    public static void main(String[] args){
    String hex;
  hex = JOptionPane.showInputDialog(null, "Enter the Binary number:");
  long num = Long.parseLong(hex);
  long rem;
  while(num > 0){
  rem = num % 10;
  num = num / 10;
  if(rem != 0 && rem != 1){
  JOptionPane.showMessageDialog(null, "This is not a binary number.","a", JOptionPane.WARNING_MESSAGE);
  JOptionPane.showMessageDialog(null, "Please try once again.","w", JOptionPane.WARNING_MESSAGE);
  System.exit(0);
  }
  }
  int i= Integer.parseInt(hex,2);
  String hexString = Integer.toHexString(i);
  JOptionPane.showMessageDialog(null, "Hexa decimal: " + hexString,"result", JOptionPane.INFORMATION_MESSAGE);
  }
}

How to center your Div tag on CSS

Here is the code for CSS

Ex.

#container {
                   width: 800px;
                   height: 900px;
                   margin-left: auto;
                   margin-right: auto:
}
The AUTO word means that it automatically center your div.

Here is the code for HTML

Ex.

<div id="container">
<div id="banner"></div>
</div>

You must put the div tag inside the div container so the banner automatically go to center.

That's all.
Thanks !