Wednesday, September 11, 2013

Java Program 009

Create a file ArithmeticTest.java which accepts three arguments- two int values and one Operator (any one of +, –, *) and Print The Following Output:

Output: 2 + 3 = 5

 

// Code NOT Tested !!

public class AdditionTest{
	public static void main(String[] args){
		int n1 = Integer.parseInt(args[0]);
		int n2 = Integer.parseInt(args[1]);
		String operator = args[2];
		
		if (operator.equals("*"))
			System.out.println(n1 + " * " + n2 + " = " + (n1 * n2));
		else if (operator.equals("+"))
			System.out.println(n1 + " + " + n2 + " = " + (n1 + n2));
		else if (operator.equals("-"))
			System.out.println(n1 + " - " + n2 + " = " + (n1 - n2));
		else
			System.out.println(" Use a Correct Third Operator");
		
		System.out.println(" Bye,");
	}
}		

Blogger Labels: Java,Program,ArithmeticTest,arguments,Operator,Print

No comments:

Post a Comment