<asp>
software tutorials
Tuesday, 1 March 2011
Monday, 28 February 2011
java programm for calculator
import java.util.Scanner;
public class calculator
{
public static void main(String[] args)
{
char answer;
String input;
int firstnumber;
int secondnumber;
System.out.println ("Welcome to the calculator!");
System.out.println ("To multiply use m, to divide use d, to add use a, to subtract use s");
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println ("Do you want to multiply, divide, add, or subtract? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
if (answer == 'm')
System.out.println ("Input first number: ");
keyboard.nextLine();
input = keyboard.nextLine();
firstnumber = keyboard.nextInt();
System.out.println ("Would you like another calculation (y/n)? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
}
while(answer == 'y')
if(answer == 'n');
System.exit(0);
}
}
public class calculator
{
public static void main(String[] args)
{
char answer;
String input;
int firstnumber;
int secondnumber;
System.out.println ("Welcome to the calculator!");
System.out.println ("To multiply use m, to divide use d, to add use a, to subtract use s");
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println ("Do you want to multiply, divide, add, or subtract? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
if (answer == 'm')
System.out.println ("Input first number: ");
keyboard.nextLine();
input = keyboard.nextLine();
firstnumber = keyboard.nextInt();
System.out.println ("Would you like another calculation (y/n)? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
}
while(answer == 'y')
if(answer == 'n');
System.exit(0);
}
}
VB.NET Error Handling
In the previous versions of VB we had several flavors of "On Error" statements to handle error in a non-structured way. But in VB.NET we can make use of the structured way of error handling with the Try & Catch statement.
Here is an example for this.
Sub DoSomething()Try'Do SomethingCatch e As Exception'Catch the error and display it.Response.Write("An Error Occurred: " & e.toString())
Finally'Do the final cleanup such as closing the Database connectionEnd Try
End Sub
Subscribe to:
Posts (Atom)