Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Monday, 18 May 2015

java program to add two numbers using different Methods


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