Wednesday, January 16, 2013

Java Program to reverse given input number


-->
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class java3 {

public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
int no,i,rev=0;
System.out.println("Please Enter the number which has to be reversed");
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
no=Integer.parseInt(br.readLine());
System.out.println("The Entered number is "+no);
while(no>0)
{
rev=rev*10;
i=no%10;
rev+=i;
no=no/10;
}
System.out.println("The Reverse Version of given number is "+rev);
}
}




In the above program class name is java3.When the program is run  Please Enter the number which has to be reversed  message is displayed.Enter a number in the console and click enter button.The value is reversed and displayed as output in the console.The output is displayed with the message The Reverse Version of given number is ,followed by the reverse of the input number
 

Thursday, January 10, 2013

HTML code with JavaScripting for performing Arithmetic Operations


The following code displays two fields for taking two input numbers and there are separate buttons for four arithmetic operations.When Clicked on a button,alert message is displayed with result and result is also updated in the page.

   Four JavaScript functions are defined in the script tag.Four functions are used for addition,subtraction,multiplication,division.Four Separate buttons are defined in the body tag.The values of the four buttons are Addition,Subtraction,Deletion and Multiplication.

        When a user clicks on the button with value Addition,Addition function is called.Addition function takes the values from the two input fields and performs addition,then alert message is displayed with result and result is also displayed in the webpage.


Check The Live Demo here or Copy,paste this url  http://jsfiddle.net/6JmuY/

<html>
<head>
<title>Arithmetic operations</title>
</head>
<script type="text/javascript">
function Addition()
{
x=parseFloat(calc.value1.value);
y=parseFloat(calc.value2.value);
z=(x+y);
alert("The Addition result is"+z);
calc.value3.value=z
}
function Subtraction()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=x-y;
alert("The subtraction result is "+z);
calc.value3.value=z
}
function Multiplication()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=x*y;
alert("The Multiplication result is "+z);
calc.value3.value=z
}
function Division()
{
var x,y,z;
x=calc.value1.value;
y=calc.value2.value;
z=x/y;
alert("The subtraction result is "+z);
calc.value3.value=z
}
</script>
</head>
<body>
<form name="calc">
<h1>Online Calculator</h1>
Enter first Numeric Value :   <input type="number" id="value1"> </br>
Enter Second Numeric Value : <input type="number" id="value2"> </br>
 </br>
Result of the Arithmetic operation is : <output type="number" id="value3"> </output></br>
<input type="button" Value="Addition" onClick=Addition()> </br>
<input type="button" Value="Subtraction" onClick=Subtraction()></br>
<input type="button" Value="Multiplication" onClick=Multiplication()></br>
<input type="button" Value="Division" onClick=Division()></br>
</form>
</body>
</html>