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 (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);
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);
}
}
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:-
{
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);
}
}
explained very well, thank you sir
ReplyDeleteclass Sis
ReplyDelete{
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);
}
}
class Sis
ReplyDelete{
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);
}
}
class Triangle
ReplyDelete{
public static void main(String args[])
{
int b=Integer.parseInt(args[0]);
int h=Integer.parseInt(args[1]);
System.out.println((b*h)/2);
}
}
class Centigrade
ReplyDelete{
public static void main(String args[])
{
int f=Integer.parseInt(args[0]);
System.out.println("c=" + (5*f-160)/9);
}
}
class Celcius
ReplyDelete{
public static void main(String args[])
{
int f=Integer.parseInt(args[0]);
System.out.println("c=" + (5*f-160)/9);
}
}
class Fahrenite
ReplyDelete{
public static void main(String args[])
{
int c=Integer.parseInt(args[0]);
System.out.println("F=" + ((c*9/5)+32));
}
}
// WAP to calculate simple interest
ReplyDeleteimport 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);
}
}
// WAP to calculate area of triangle
ReplyDeleteimport 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);
}
}
//WAP to calculate area of circle
ReplyDeleteimport 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);
}
}
// WAP swapping two numbers
ReplyDeleteimport 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);
}
}
// WAP to calculate square and cube
ReplyDeleteimport 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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 );
}
}
import java.util.Scanner;
ReplyDeleteclass 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 );
}
}
Q:- WAP to calculate simple interest using Command Line Input ?
ReplyDeleteSolution:-
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);
}
}
Q:- WAP to calculate area of triangle using Command Line Input ?
ReplyDeleteSolution:-
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);
}
}
class Cmd
ReplyDelete{
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);
}
}
class Tri
ReplyDelete{
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);
}
}
class Sr
ReplyDelete{
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);
}
}
class Sw
ReplyDelete{
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);
}
}
class simpleInt
ReplyDelete{
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);
}
}
class triangle
ReplyDelete{
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);
}
}
class Area
ReplyDelete{
public static void main(String args[])
{
float r=Float.parseFloat(args[0]);
float a=3.14f*r*r;
System.out.println(a);
}
}
class squre
ReplyDelete{
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);
}
}
class swap
ReplyDelete{
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);
}
}
Nitesh bamotriya
ReplyDeletecalculate 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);
}
}
Nitesh bamotriya
ReplyDeleteimport 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 );
Nitesh bamotriya
ReplyDeleteclass 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);
}
//WAP to calculate simple interest using Command Line Input?
ReplyDeleteclass 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);
}
}
class AreaOfTri
ReplyDelete{
public static void main(String args[])
{
int b=Integer.parseInt(args[0]);
int h=Integer.parseInt(args[1]);
System.out.println((b*h)/2);
}
}
class SimpleInterest{
ReplyDeletepublic 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);
}
}
2) WAP to calculate the area of Triangle using Command Line Input?
ReplyDeleteclass 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);
}
}
#nancy purwar
ReplyDelete3) 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);
}
}
#nancy purwar
ReplyDelete# 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 );
}
}
#nancy purwar
ReplyDeleteWAP 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);
}
}
//WAP to calculate the area of Triangle using Command Line Input?
ReplyDeleteclass 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);
}
}
//WAP to calculate the Swap program using Command Line Input?`
ReplyDeleteclass 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);
}
}
-WAP to calculate simple interest using Command Line Input?
ReplyDeleteclass 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);
}
}
-WAP to calculate the Swap program using Command Line Input?`
ReplyDeleteclass 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);
}
}
-WAP to calculate the area of Triangle using Command Line Input?
ReplyDeleteclass 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);
}
}
-WAP to calculate Area of Circle using Command Line Input?
ReplyDeleteclass 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);
}
}
//wap to calculate cube and square root using command line input
ReplyDeleteclass 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);
}
}
//wap to swap two no using command line input
ReplyDeleteclass 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);
}
}
//wap to calculate area of Circle using command line input
ReplyDeleteclass 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);
}
}
//wap to calculate area of triangle using command line input
ReplyDeleteclass 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);
}
}
//WAP to calculate simple interest using command line input
ReplyDeleteclass 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);
}
}
Ankita Verma
ReplyDeleteclass 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);
}
}
ReplyDeleteAnkita 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");
}
}
}
ReplyDeleteAnkita 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);
}
}
ReplyDeleteAnkita 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);
}
}
ReplyDeleteAnkita 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);
}
}
ReplyDeleteAnkita 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);
}
}
ReplyDeleteAnkita 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
import java.util.Scanner;
ReplyDeleteclass 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);
}
}
// yogesh seroke
ReplyDelete//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);
}
}
//yogesh seroke
ReplyDelete//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);
}
}
//yogesh seroke
ReplyDelete//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);
}
}
//yogesh seroke
ReplyDelete//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);
}
}
//yogesh seroke
ReplyDelete//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);
}
}
Sandeep kelwa
ReplyDeleteimport 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.*;
}
}
Sandeep kelwa
ReplyDeleteimport 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);
}
}