Posts

Showing posts from 2013

Program 3 : Addition of 2 integer number which is given by the user using command line window.

Program :  Create a Java Program that make the Addition of 2 integer number which is given by the user using command line window. Solution : class SabTech { public static void main(String args[])     { if(args.length!=2) { System.out.println("Not enough arguments...Please Pass Exactly TWO arguments..."); System.exit(0); } int no1=Integer.parseInt(args[0]); int no2=Integer.parseInt(args[1]); int ans; ans=no1+no2; System.out.println("Addition of " + no1 + " and " + no2 + " is ==> " + ans); } } O/P: >javac SabTech.java >java SabTech 15 12 Addition of 15 and 12 is ==> 27

Program 2 : Getting Values from user on Command line Window.

Program :  Create a Java Program that Get Values from user on Command line Window. Solution : Here First we are displaying all the values which are entered by the user on command line window.               class SabTech               {                      public static void main(String args[])                      {                             int i;                             for(i=0;i<args.length;i++)                             {                                   System.out.println("Argument " + i + " is ==> " + args[i]);                             }                      }               } O/P: >javac SabTech.java >java SabTech  Sabarmati Technology  123 Argument 0 is ==> Sabarmati Argument 1 is ==> Technology Argument 2 is ==> 123

Program 1 : Create a Java Program that display "Hello World" on your command line window.

Program :  Create a Java Program that display "Hello World" on your command line window. Solution : Steps to create a Java Program:         1. Create new text file using notepad.         2. Now write given below code to your notepad file.               class SabTech               {                      public static void main(String args[])                      {                     System.out.println("Hello World");              }               }        3. Now save this file using "SabTech.java" . How to Compile and Run Java Program:        1.  Open Command-line window.        2. To COMPILE your java Program write below code:-                       " javac SabTech.java"            Then press Enter.            So Now in your Folder a one new File Created with Name "SabTech.class"        3. Now to RUN your java Program write below code:-                       " java SabTech"