simple arithmetic using command line argument
1
class CommanLine
{ public static void main(String args[]){
int a,b,c=0;
a=Integer.parseInt(a[0]);
b=Integer.parseInt(a[1]);
c=a+b;
5 System.out.println("sum is"+c);
7 }
8 }
using scanner
import java.util.Scanner;
class Add_CMD {
public static void main(String[] args){
int a,b,c;
System.out.println("Enter integers ");
Scanner in = new Scanner(System.in);
a = in.nextInt();
b = in.nextInt();
c=a+b;
System.out.println("Sum of " + a+ " and " + b + " is " +c);
}
}
using BufferedReader
import java.io.*;
class Arithmatic
{
public static void main(String args[])throws IOException
{
try
{
int a,b,c,ae,nfe;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
a=Integer.parseInt(br.readLine());
b=Integer.parseInt(br.readLine());
c=a/b;
System.out.println("Result="+c);
}
/*catch(ArithmeticException ae)
{
System.out.println("eror due to"+ ae.getMessage());
}
catch(NumberFormatException nfe)
{
System.out.println("error due to"+ nfe.getMessage());
}*/
catch(Exception nfe)
{
System.out.println("error due to"+ nfe.getMessage());
}
}}
No comments:
Post a Comment