How to take input in Java?

68

Java provides
java.lang package and System class to take input from users and display output on an output device.

                               java.lang   (package)

                                                          Object     (Super Class)

                                                                     System      (Sub Class)
PrintStream(It is used to manage output operation)          InputStream(It is used to manage input operation)
print()                                                                                    read()
println()

PrintStream out;
out is the reference variable of PrintStream class which is used to access print() or println()
System.out.print()       // display output without new line char \n
System.out.println();  // display output with new line char  \n 
InputStream in;
"in" is the reference of InputStream class which will be used to call read() for input operation
System.in.read();
but read() return byte data and throw exception IOException hence System.in reference will be managed by the Scanner class which will store input data in an Object pattern.
Scanner sc = new Scanner(System.in);
note:-  Scanner is not used to take input, it will only manage input data of System.in reference hence Scanner is also called Input Manager Class.
Scanner class provides a predefined method to convert object type to another data type of Java.
int a = sc.nextInt()  //Scanner object data to integer
float b = sc.nextFloat()  //float
double d = sc.nextDouble()  //double
String s = sc.next();   //string
String s1 = sc.nextLine();  //paragraph
Example of System.in.read()?
import java.io.*;
class InputDemo
{
   public static void main(String args[]) throws IOException
   {
       int a = System.in.read();
       System.out.println((char)a);

    }
}
...................................................................................

Scanner class Example to manage integer and char input operation:-
import java.util.*;
class InputDemo
{
    public static void main(String scs[])
    {
        Scanner st = new Scanner(System.in);
        System.out.println("Enter int");
        int a1 =st.nextInt();
        System.out.println(a1);
        System.out.println("Enter char");
        char a2 =st.next().charAt(0);
        System.out.println(a2);
    }
}
Another Example of Scanner Class in Java:-
import java.util.Scanner;
class InputDemo
{
   public static void main(String args[])
   {
            Scanner sc = new Scanner(System.in);   // System.in is mandatory to pass under Scanner Objectg
       System.out.println("enter first number");
       int a = sc.nextInt();
       System.out.println("enter second number");
       int b = sc.nextInt();
       System.out.println(a+b);
    }
}
Scanner class Example with all datatype:-
import java.util.Scanner;
class AllInput
{
   public static void main(String args[])
   {
          int a;
          char ch;
          String s;
          float f;
          double d;
          Object o;
          Integer i;
          Float f1;
          Scanner sc = new Scanner(System.in);
          System.out.println("enter int, char, string, float, double, object, 
Integer, Float ");
         a = sc.nextInt();
         ch = sc.next().charAt(0);
         s = sc.next();
         f = sc.nextFloat();
         d = sc.nextDouble();
         o = sc.next();
         i = sc.nextInt();
         f1 = sc.nextFloat();
         System.out.println("a = "+a + "ch = "+ch + "s = "+s + "f = "+f + "d="+d+" 

o="+o+" i="+i + "f="+f1);
           }
}
......................................................................................................................................................................
Using Command Prompt:-
The command prompt is a very old approach to take input from users, this is used on command-line interface-based software.
DOS is the best example of command-line input,  we can manage all DOS operations using a set of commands.
The database also works using a terminal that is the command-based software system.
Java provides a parametrized String array under main() to handle command-line input.
Java can not create multiple types of main() hence it has created a single main() to perform all tasks.
public static void main(String args[])   //here args[] is the string array
{
}
 Create program:-
class InputExample2
{
   public static void main(String args[])
   {
        String s = args[0];
        String s1 = args[1];
        System.out.println("value is "+s + " value is "+s1);
   }
}
Compile
javac InputExample2.java
java InputExample2 "hello" "12.345"
Program of addition using Command Prompt Input
class InputExample2
{
   public static void main(String args[])
   {
        int s = Integer.parseInt(args[0]);
        int s1 =Integer.parseInt(args[1]);
        System.out.println(s+s1);
   }
}
Another Example of Command-Line input in java:-
class CommandInput
{
   public static void main(String args[])
   {
       // System.out.println(args[0] + "," + args[1] + " ," + args[2]);
        for(String s:args)
        {
            System.out.println(s);
        }   

    }
}
java provides the Wrapper class to convert the primitive data type to object type.
Integer, Float, Double, Character, Boolean is the Wrapper class of Java.
parseInt() method to convert Object to Integer  or String to integer using Integer.parseInt()
parseFloat() method to convert Object to float or String to float using Float.parseFloat().
Assignments of Command-Line Input In Java?
1)  WAP to calculate simple interest using Command Line Input?
2)  WAP to calculate the area of Triangle using Command Line Input?
3) WAP to calculate Area of Circle using Command Line Input?
4)  WAP to calculate the Swap program using Command Line Input?
5)  WAP to calculate Square and Cube using Command Line Input?

How to take input from user's in Stream Class:-
import java.io.*;
class StreamInput
{
   public static void main(String args[]) throws IOException
   {       
       InputStreamReader ir = new InputStreamReader(System.in);
       BufferedReader br = new BufferedReader(ir);
       String s = br.readLine();
       System.out.println(s); 
   }
}
Tags

إرسال تعليق

68تعليقات

POST Answer of Questions and ASK to Doubt

  1. explained very well, thank you sir

    ردحذف
  2. class Sis
    {
    public static void main(String args[])
    {
    int p =Integer.parseInt(args[500]);
    int t =Integer.parseInt(args[2]);
    int r =Integer.parseInt(args[5]);
    System.out.println((p*t*r)/100);
    }
    }

    ردحذف
  3. class Sis
    {
    public static void main(String args[])
    {
    int p =Integer.parseInt(args[0]);
    int t =Integer.parseInt(args[1]);
    int r =Integer.parseInt(args[2]);
    System.out.println((p*t*r)/100);
    }
    }

    ردحذف
  4. class Triangle
    {
    public static void main(String args[])
    {
    int b=Integer.parseInt(args[0]);
    int h=Integer.parseInt(args[1]);
    System.out.println((b*h)/2);
    }
    }

    ردحذف
  5. class Centigrade
    {
    public static void main(String args[])
    {
    int f=Integer.parseInt(args[0]);
    System.out.println("c=" + (5*f-160)/9);
    }
    }

    ردحذف
  6. class Celcius
    {
    public static void main(String args[])
    {
    int f=Integer.parseInt(args[0]);
    System.out.println("c=" + (5*f-160)/9);
    }
    }

    ردحذف
  7. class Fahrenite
    {
    public static void main(String args[])
    {
    int c=Integer.parseInt(args[0]);
    System.out.println("F=" + ((c*9/5)+32));
    }
    }

    ردحذف
  8. // WAP to calculate simple interest
    import java.util.Scanner;
    class Sii
    {
    public static void main(String[] args)
    {
    Scanner h = new Scanner(System.in);
    System.out.println("Enter principal amount");
    int p = h.nextInt();
    System.out.println("Enter rate of interest");
    float r = h.nextFloat();
    System.out.println("Enter time duration (in year)");
    float t = h.nextFloat();
    float si = (p*r*t)/100;
    System.out.println("Simple Interest is = "+si);
    }
    }

    ردحذف
  9. // WAP to calculate area of triangle
    import java.util.Scanner;
    class Artriangle
    {
    public static void main(String...area)
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter base of triangle");
    int b = sc.nextInt();
    System.out.println("Enter height of triangle");
    int h = sc.nextInt();
    float ar = 0.5F*(b*h);
    System.out.println("Area of triangle is = "+ar);
    }
    }

    ردحذف
  10. //WAP to calculate area of circle
    import java.util.Scanner;
    class Arcircle
    {
    public static void main(String...area)
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter radius of circle");
    int r = sc.nextInt();
    float ar = 3.14F*r*r;
    System.out.println("Area of circle is = "+ar);
    }
    }

    ردحذف
  11. // WAP swapping two numbers
    import java.util.Scanner;
    class Swapping
    {
    public static void main(String...area)
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter 1st no.");
    int f = sc.nextInt();
    System.out.println("Enter 2nd no.");
    int s = sc.nextInt();
    System.out.println("Before swapping 1st no = "+f+" and 2nd no = "+s);
    int a = f;
    f = s;
    s = a;
    System.out.println("After swapping 1st no = "+f+" and 2nd no = "+s);
    }
    }

    ردحذف
  12. // WAP to calculate square and cube
    import java.util.Scanner;
    class SqCb
    {
    public static void main(String...area)
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter a no.");
    int a = sc.nextInt();
    int s = a*a;
    System.out.println("Square of "+a+" is = "+s);
    int c = a*a*a;
    System.out.println("Cube of "+a+" is = "+c);
    }
    }

    ردحذف
  13. import java.util.Scanner;
    class Si
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);
    System.out.println("enter first number");
    int p = sc.nextInt();
    System.out.println("enter second number");
    int t = sc.nextInt();
    System.out.println("enter third number");
    int r = sc.nextInt();


    System.out.println("Simpleinterest=" +p*t*r/100);

    }


    }

    ردحذف
  14. import java.util.Scanner;
    class Tri
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);
    System.out.println("base");
    int a = sc.nextInt();
    System.out.println("height");
    int b = sc.nextInt();



    System.out.println("Area of triangle=" +a*b/2);

    }


    }

    ردحذف
  15. import java.util.Scanner;
    class Circle
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);

    System.out.println("r");
    int a = sc.nextInt();



    System.out.println("Area of circle=" +3.14*a*a);

    }


    }

    ردحذف
  16. import java.util.Scanner;
    class Sq
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);

    System.out.println("num");
    int a = sc.nextInt();

    System.out.println("sq=" +a*a );



    }


    }

    ردحذف
  17. import java.util.Scanner;
    class Qb
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);

    System.out.println("num");
    int a = sc.nextInt();

    System.out.println("cube=" +a*a*a );



    }


    }

    ردحذف
  18. Q:- WAP to calculate simple interest using Command Line Input ?
    Solution:-
    import java.util.Scanner;
    class Sis
    {
    public static void main(String args[])
    {
    Scanner si = new Scanner(System.in);
    System.out.println("Enter Principle Ammount :- ");
    int p = si.nextInt();
    System.out.println("Enter Duration in Year :- ");
    int t = si.nextInt();
    System.out.println("Enter Rate of Interest");
    int r = si.nextInt();
    System.out.println("The Simple Interest is :- ");
    System.out.println((p*t*r)/100);
    }
    }

    ردحذف
  19. Q:- WAP to calculate area of triangle using Command Line Input ?
    Solution:-
    import java.util.Scanner;
    class Triangle
    {
    public static void main(String args[])
    {
    Scanner at = new Scanner(System.in);
    System.out.println("Enter Breath :- ");
    int b = at.nextInt();
    System.out.println("Enter Height :- ");
    int h = at.nextInt();
    System.out.println("The Area of Triangle is :- ");
    System.out.println((b*h)/2);
    }
    }

    ردحذف
  20. class Cmd
    {
    public static void main(String arg[])
    {
    int p=Integer.parseInt(arg[0]);
    int r=Integer.parseInt(arg[1]);
    int t=Integer.parseInt(arg[2]);
    int si=p*r*t/100;
    System.out.println(si);
    }
    }

    ردحذف
  21. class Tri
    {
    public static void main(String arg[])
    {
    int b=Integer.parseInt(arg[0]);
    int h=Integer.parseInt(arg[1]);
    int a=b*h/2;
    System.out.println(a);
    }
    }

    ردحذف
  22. class Sr
    {
    public static void main(String arg[])
    {
    int p=Integer.parseInt(arg[0]);
    int r=Integer.parseInt(arg[1]);
    int a=p*r;
    System.out.println(a);
    }
    }

    ردحذف
  23. class Sw
    {
    public static void main(String arg[])
    {
    int c;
    int a=Integer.parseInt(arg[0]);
    int b=Integer.parseInt(arg[1]);
    c=b;
    b=a;
    b=c;



    System.out.println("a"+a);
    System.out.println("b"+b);
    }
    }

    ردحذف
  24. class simpleInt
    {

    public static void main(String args[])
    {
    int p= Integer.parseInt(args[0]);
    int r= Integer.parseInt(args[1]);
    int t= Integer.parseInt(args[2]);
    int s=p*r*t/100;
    System.out.println(s);
    }
    }

    ردحذف
  25. class triangle
    {
    public static void main(String args[])
    {

    int h=Integer.parseInt(args[0]);
    int b=Integer.parseInt(args[1]);
    int a=h*b/2;
    System.out.println(a);

    }

    }

    ردحذف
  26. class Area
    {
    public static void main(String args[])
    {

    float r=Float.parseFloat(args[0]);

    float a=3.14f*r*r;

    System.out.println(a);

    }
    }

    ردحذف
  27. class squre
    {
    public static void main(String args[])
    {
    int a=Integer.parseInt(args[0]);
    int c=Integer.parseInt(args[1]);
    int x=a*a;
    int y=c*c*c;
    System.out.println("Area of="+x);
    System.out.println("cube of="+y);
    }
    }

    ردحذف
  28. class swap
    {
    public static void main(String args[])
    {
    int x=Integer.parseInt(args[0]);
    int y=Integer.parseInt(args[1]);
    int z;
    z=x;
    x=y;
    y=z;
    System.out.println("x="+x);
    System.out.println("y="+y);
    }
    }

    ردحذف
  29. Nitesh bamotriya
    calculate simple interest
    import java.util.Scanner;
    class Sii
    {
    public static void main(String[] args)
    {
    Scanner h = new Scanner(System.in);
    System.out.println("Enter principal amount");
    int p = h.nextInt();
    System.out.println("Enter rate of interest");
    float r = h.nextFloat();
    System.out.println("Enter time duration (in year)");
    float t = h.nextFloat();
    float si = (p*r*t)/100;
    System.out.println("Simple Interest is = "+si);
    }
    }

    ردحذف
  30. Nitesh bamotriya
    import java.util.Scanner;
    class Qb
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);

    System.out.println("num");
    int a = sc.nextInt();

    System.out.println("cube=" +a*a*a );

    ردحذف
  31. Nitesh bamotriya
    class Circle
    {
    public static void main(String args[])
    {

    Scanner sc = new Scanner(System.in);

    System.out.println("r");
    int a = sc.nextInt();



    System.out.println("Area of circle=" +3.14*a*a);

    }

    ردحذف
  32. //WAP to calculate simple interest using Command Line Input?
    class SI
    {
    public static void main(String args[])
    {
    int p = Integer.parseInt(args[0]);
    int r = Integer.parseInt(args[1]);
    int t = Integer.parseInt(args[2]);
    System.out.println((p*r*t)/100);
    }
    }

    ردحذف
  33. class AreaOfTri

    {
    public static void main(String args[])
    {
    int b=Integer.parseInt(args[0]);
    int h=Integer.parseInt(args[1]);
    System.out.println((b*h)/2);
    }
    }

    ردحذف
  34. class SimpleInterest{

    public static void main(String[] args)
    {

    double p,r,t,SI;
    p=Double.parseDouble(args[0]);
    r=Double.parseDouble(args[1]);
    t=Double.parseDouble(args[2 ]);
    SI=(p*r*t)/100;
    System.out.println("Simple interet"+SI);



    }

    }

    ردحذف
  35. 2) WAP to calculate the area of Triangle using Command Line Input?


    class Triangle{

    public static void main(String args[])
    {

    int b=Integer.parseInt(args[0]);
    int h=Integer.parseInt(args[1]);
    int area=(b*h)/2;
    System.out.println("Area of triangle:"+area);
    }
    }

    ردحذف
  36. #nancy purwar


    3) WAP to calculate Area of Circle using Command Line Input?


    class Circle{

    public static void main(String args[])
    {

    int r=Integer.parseInt(args[0]);
    float area=3.14f*r*r;
    System.out.println("Area of circle:"+area);
    }
    }

    ردحذف
  37. #nancy purwar

    # WAP to calculate the Swap program using Command Line Input?

    class SwapCommandLine
    {

    public static void main(String[] args) {

    int a= Integer.parseInt(args[0]);
    int b= Integer.parseInt(args[1]);
    System.out.println("Before swapping value of a="+a );
    System.out.println("Before swapping value of b="+b );

    a=a+b;
    b=a-b;
    a=a-b;
    System.out.println("after swapping value of a="+a );
    System.out.println("after swapping value of b="+b );



    }
    }

    ردحذف
  38. #nancy purwar

    WAP to calculate Square and Cube using Command Line Input?

    class Square1
    {
    public static void main(String[] args)
    {

    int a=Integer.parseInt(args[0]);
    int square= a*a;
    System.out.println("square:"+square);
    int cube=a*a*a;
    System.out.println("Cube:"+cube);

    }
    }

    ردحذف
  39. //WAP to calculate the area of Triangle using Command Line Input?

    class Areaoftriangle
    {
    public static void main(String args[])
    {
    int b = Integer.parseInt(args[0]);
    int h = Integer.parseInt(args[1]);
    System.out.println((b*h)/2);
    }
    }

    ردحذف
  40. //WAP to calculate the Swap program using Command Line Input?`
    class Swap
    {
    public static void main(String args[])
    {
    int num1=Integer.parseInt(args[0]);
    int num2=Integer.parseInt(args[1]);
    int temp;
    temp=num1;
    num1=num2;
    num2=temp;

    System.out.println(num1+" "+num2);
    }
    }

    ردحذف
  41. -WAP to calculate simple interest using Command Line Input?

    class SI
    {
    public static void main(String args[])
    {
    int p =Integer.parseInt(args[0]);
    int t =Integer.parseInt(args[1]);
    int r =Integer.parseInt(args[2]);
    System.out.println((p*t*r)/100);
    }
    }

    ردحذف
  42. -WAP to calculate the Swap program using Command Line Input?`

    class Swapping
    {
    public static void main(String args[])
    {
    int a=Integer.parseInt(args[0]);
    int b=Integer.parseInt(args[1]);
    int c;
    c=a;
    a=b;
    b=c;

    System.out.println("After Swapping "+"a= "+ a +" b= "+b);
    }
    }

    ردحذف
  43. -WAP to calculate the area of Triangle using Command Line Input?

    class Area
    {
    public static void main(String args[])
    {
    int base = Integer.parseInt(args[0]);
    int height = Integer.parseInt(args[1]);
    System.out.println((base*height)/2);
    }
    }

    ردحذف
  44. -WAP to calculate Area of Circle using Command Line Input?

    class Areaofcircle
    {
    public static void main(String args[])
    {
    int r = Integer.parseInt(args[0]);
    double area = 3.14*r*r;
    System.out.println("Area of Cicle = " +area);
    }
    }

    ردحذف
  45. //wap to calculate cube and square root using command line input

    class CSRoot
    {
    public static void main(String args[])
    {
    Integer n,s,c;
    n=Integer.parseInt(args[0]);
    s=n*n;
    c=n*n*n;
    System.out.println("Square of no is = "+s);
    System.out.println("Cube of no is = "+c);
    }
    }

    ردحذف
  46. //wap to swap two no using command line input

    class SwapTwoNo
    {
    public static void main(String args[])
    {
    int a,b,c;
    a=Integer.parseInt(args[0]);
    b=Integer.parseInt(args[1]);
    System.out.println("Before Swapping a="+a+" b="+b);
    c=a;
    a=b;
    b=c;
    System.out.println("After Swapping a="+a+" b="+b);
    }
    }

    ردحذف
  47. //wap to calculate area of Circle using command line input

    class AreaOfCircle
    {
    public static void main(String args[])
    {
    float ar,r;
    r=Float.parseFloat(args[0]);
    ar=r*r*3.14F;
    System.out.println("Radius is = "+r);
    System.out.println("Area of Circle is = "+ar);
    }
    }

    ردحذف
  48. //wap to calculate area of triangle using command line input

    class AreaOfTriangle
    {
    public static void main(String args[])
    {
    float ar,b,h;
    b=Float.parseFloat(args[0]);
    h=Float.parseFloat(args[1]);
    ar=(b*h)*0.5F;
    System.out.println("Base is = "+b);
    System.out.println("Height is = "+h);
    System.out.println("Area of Triangle is = "+ar);
    }
    }

    ردحذف
  49. //WAP to calculate simple interest using command line input

    class SimpleInterest {
    public static void main (String args[]) {
    float si, p, r, t;
    p=Float.parseFloat(args[0]);
    r=Float.parseFloat(args[1]);
    t=Float.parseFloat(args[2]);
    si=(p*r*t)100F;
    System.out.println("Principal is = "+p);
    System.out.println("Rate is = "+r);
    System.out.println("Time is = "+t);
    System.out.println("Simple Interest is = "+si);
    }
    }

    ردحذف
  50. Ankita Verma

    class Leapyear
    {
    public static void main(String args[])
    {

    int year=1991;

    String s=(year%4==0)||(year%100!=0)||(year%400==0)?"Leap year":"not a Leap year";

    System.out.println(s);
    }
    }

    ردحذف

  51. Ankita Verma

    class Weak
    {
    public static void main(String args[])
    {
    char ch='7';

    switch(ch)
    {
    case'1':
    System.out.println("Today is Monday");
    break;

    case'2':
    System.out.println("Today is Tuesday");
    break;

    case'3':
    System.out.println("Today is Wednesday");
    break;

    case'4':
    System.out.println("Today is Thursday");
    break;

    case'5':
    System.out.println("Today is Friday");
    break;

    case'6':
    System.out.println("Today is Saturday");
    break;

    case'7':
    System.out.println("Today is Sunday");
    break;

    default:
    System.out.println("Invalidday");
    }
    }
    }

    ردحذف

  52. Ankita Verma
    import java.util.Scanner;

    class InputExample1
    {

    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);

    System.out.println("Enter the value of principle");
    int p = sc.nextInt();
    System.out.println("Enter the value of rate");
    float r= sc.nextFloat();
    System.out.println("Enter the value of time duration");
    float t = sc.nextFloat();

    float si=(p*t*r)/100;
    System.out.println("Simple interest is=" +si);

    }
    }

    ردحذف


  53. Ankita Verma

    import java.util.Scanner;
    class SqCube
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the value");
    int a= sc.nextInt();

    int sq =a*a;
    int c=a*a*a;

    System.out.println("squre is=" +sq);

    System.out.println("cube is=" +c);

    }
    }

    ردحذف



  54. Ankita Verma

    import java.util.Scanner;
    class Area
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter breadth");
    int b= sc.nextInt();
    System.out.println("Enter height");
    int h= sc.nextInt();
    int A=(b*h)/2;
    System.out.println("Area of triangle=" +A);


    }
    }

    ردحذف

  55. Ankita Verma

    import java.util.Scanner;
    class AreaCircle
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the value of pi");
    float p= sc.nextFloat();
    System.out.println("Enter radius");
    int r= sc.nextInt();
    float AC=p*r*r;
    System.out.println("Area of Circle=" +AC);


    }
    }

    ردحذف

  56. Ankita Verma
    import java.util.Scanner;
    class Swapping
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the First value");
    int a= sc.nextInt();
    System.out.println("Enter the Second value");
    int b= sc.nextInt();
    a=a+b;
    b=a-b;
    a=a-b;
    System.out.println("Swap the value a & b" + " " + a + " " + b);



    }
    }

    ردحذف
  57. import java.util.Scanner;
    class SI
    {
    public static void main(String args[])
    {
    int p,t,r;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter Principle Ammount= ");
    p = sc.nextInt();
    System.out.println("Enter Time= ");
    t = sc.nextInt();
    System.out.println("Enter Rate of Interest");
    r =sc.nextInt();

    int si=((p*t*r)/100);
    System.out.println("The Simple Interest is =" + si);
    }
    }

    ردحذف
  58. import java.util.Scanner;
    class Area
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter base of triangle");
    int b = sc.nextInt();
    System.out.println("Enter height of triangle");
    int h = sc.nextInt();
    int ar = (b*h);
    System.out.println("Area of triangle is = "+ar);
    }
    }

    ردحذف
  59. import java.util.Scanner;
    class Circle
    {
    public static void main(String []args)
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter radius of circle");
    int r = sc.nextInt();
    float ar = 3.14F*r*r;
    System.out.println("Area of circle is = "+ar);
    }
    }

    ردحذف
  60. import java.util.Scanner;
    class Swap
    {
    public static void main(String[]abc)
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter first no. =");
    int g= sc.nextInt();
    System.out.println("Enter secand no.");
    int h= sc.nextInt();
    int a = g;
    g = h;
    h = a;
    System.out.println("After swapping 1st no = "+g+" and 2nd no = "+h);
    }
    }

    ردحذف
  61. import java.util.Scanner;
    class SQCB1
    {
    public static void main(String abc[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter a no.");
    int a = sc.nextInt();
    int s = a*a;
    System.out.println("Square of "+a+" is = "+s);
    int c = a*a*a;
    System.out.println("Cube of "+a+" is = "+c);
    }
    }

    ردحذف
  62. // yogesh seroke
    //WAP to calculate simple interest using command line input

    class SimpleInterest {
    public static void main (String args[]) {
    float si, p, r, t;
    p=Float.parseFloat(args[0]);
    r=Float.parseFloat(args[1]);
    t=Float.parseFloat(args[2]);
    si=(p*r*t)100F;
    System.out.println("Principal is = "+p);
    System.out.println("Rate is = "+r);
    System.out.println("Time is = "+t);
    System.out.println("Simple Interest is = "+si);
    }
    }

    ردحذف
  63. //yogesh seroke
    //wap to calculate area of triangle using command line input

    class AreaOfTriangle
    {
    public static void main(String args[])
    {
    float ar,b,h;
    b=Float.parseFloat(args[0]);
    h=Float.parseFloat(args[1]);
    ar=(b*h)*0.5F;
    System.out.println("Base is = "+b);
    System.out.println("Height is = "+h);
    System.out.println("Area of Triangle is = "+ar);
    }
    }

    ردحذف
  64. //yogesh seroke
    //wap to calculate area of Circle using command line input

    class AreaOfCircle
    {
    public static void main(String args[])
    {
    float ar,r;
    r=Float.parseFloat(args[0]);
    ar=r*r*3.14F;
    System.out.println("Radius is = "+r);
    System.out.println("Area of Circle is = "+ar);
    }
    }

    ردحذف
  65. //yogesh seroke
    //wap to swap two no using command line input

    class SwapTwoNo
    {
    public static void main(String args[])
    {
    int a,b,c;
    a=Integer.parseInt(args[0]);
    b=Integer.parseInt(args[1]);
    System.out.println("Before Swapping a="+a+" b="+b);
    c=a;
    a=b;
    b=c;
    System.out.println("After Swapping a="+a+" b="+b);
    }
    }

    ردحذف
  66. //yogesh seroke
    //wap to calculate cube and square root using command line input

    class CSRoot
    {
    public static void main(String args[])
    {
    Integer n,s,c;
    n=Integer.parseInt(args[0]);
    s=n*n;
    c=n*n*n;
    System.out.println("Square of no is = "+s);
    System.out.println("Cube of no is = "+c);
    }
    }

    ردحذف
  67. Sandeep kelwa

    import java.util.*;
    class InputDemo
    {
    public static void main(String scs[])
    {
    Scanner st = new Scanner(System.in);
    System.out.println("Enter int");
    int a1 =st.nextInt();
    System.out.println(a1);
    System.out.printimport java.util.*;
    }
    }


    ردحذف
  68. Sandeep kelwa
    import java.util.*;
    class NewInput
    {
    public static void main(String args[])
    {
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter first number");
    int a = sc.nextInt();
    System.out.println("Enter second number");
    int b = sc.nextInt();
    System.out.println(a+b);
    }
    }

    ردحذف
إرسال تعليق