Академический Документы
Профессиональный Документы
Культура Документы
//adding numbers
System.out.println("Adding");
System.out.println("i+j="+(i+j));
System.out.println("x + y = " + (x + y));
//subtracting numbers
System.out.println("Subtracting");
System.out.println("i-j="+(i-j));
System.out.println("x-y="+(x-y));
//multiplying numbers
System.out.println("Multiplying");
System.out.println("i*j="+(i*j));
System.out.println("x*y="+(x*y));
//dividing numbers
System.out.println("Dividing");
System.out.println("i/j="+(i/j));
System.out.println("x/y="+(x/y));
}
}
****************ArithmeticProg Output******************
C:\Mayank>javac ArithmeticProg.java
C:\Mayank>java ArithmeticProg
Adding
i+j=30
x + y = 31.0
Subtracting
i-j=-10
x-y=-10.0
Multiplying
i*j=200
x*y=215.25
Dividing
i/j=0
x/y=0.5121951219512195
Modulus
i%j=10
x%j=10.5
/* Program of Bool1 */
C:\Mayank>javac Bool1.java
C:\Mayank>java Bool1
A|B=true
A&B=false
!A=false
A^B=true
(A|B)&A=true
/* Program of simple example */
class example
{
public static void main(String args[])
{
System.out.println("Hello world");
}
}
**************Example Output****************
C:\Mayank>javac example.java
C:\Mayank>java example
Hello world
/* Program of exaple1 */
class example1
{
public static void main(String args[])
{
System.out.println("Hello all");
System.out.println("Welcome in new world of java");
}
}
********************example1 Output*********************
C:\Mayank>javac example1.java
C:\Mayank>java example1
Hello all
Welcome in new world of java
/* Program of example 2 */
class example2
{
public static void main(String args[])
{
System.out.print("\nHello all");
System.out.print("\nWelcome in new world of java");
}
}
******************Example 2 Output*****************
C:\Mayank>javac example2.java
C:\Mayank>java example2
Hello all
Welcome in new world of java
/* Program of example 3 */
class example3
{
public static void main(String args[])
{
System.out.print("Hello all");
System.out.print("Welcome in new world of java");
}
}
****************example 3 Output******************
C:\Mayank>javac example3.java
C:\Mayank>java example3
Hello allWelcome in new world of java
/* Program of example 4 */
class example4
{
public static void main(String args[])
{
System.out.print("\nHello"+"all");
System.out.print("\nWelcome in new world of java");
}
}
**************example 4 Output**************
C:\Mayank>javac example4.java
C:\Mayank>java example4
Helloall
Welcome in new world of java
/* Program of Hello */
C:\Mayank>javac Hello.java
C:\Mayank>java Hello
Hellowhoever you are
/* Program of Hello 1 */
else if (args.length==2)
{
System.out.print(args[0]);
System.out.print(" ");
System.out.print(args[1]);
}
else if (args.length==3)
{
System.out.print(args[0]);
System.out.print(" ");
System.out.print(args[1]);
System.out.print(" ");
System.out.print(args[2]);
}
else if(args.length==4)
{
System.out.print(args[0]);
System.out.print(" ");
System.out.print(args[1]);
System.out.print(" ");
System.out.print(args[2]);
System.out.print(" ");
System.out.print(args[3]);
}
else
{
System.out.print(args[0]);
System.out.print(" ");
System.out.print(args[1]);
System.out.print(" ");
System.out.print(args[2]);
System.out.print(" ");
System.out.print(args[3]);
System.out.print("and all the rest!");
}
System.out.println();
}
}
*************Hello1 Output****************
C:\Mayank>javac Hello1.java
C:\Mayank>java Hello1
HelloWhoever you are
class J03E01
{
public static void main(String args[])
{
System.out.println(
"In Java the smallest int value is "+ Integer.MIN_VALUE);
System.out.println(
"In JAVA the largest int value is "+ Integer.MAX_VALUE);
}
}
****************J03E01 Output**************
C:\Mayank>javac J03E01.java
C:\Mayank>java J03E01
In Java the smallest int value is-2147483648
In JAVA the largest int value is2147483647
/* Program of J03E02 */
class J03E02
{
public static void main(String args[])
{
int number=Integer.MAX_VALUE-2;
int count=0;
while(count<5)
{
System.out.println(number);
number++;
count++;
}
}
}
****************J03E02 Output***************
C:\Mayank>javac J03E02.java
C:\Mayank>java J03E02
2147483645
2147483646
2147483647
-2147483648
-2147483647
/* Program of J03E04 */
class J03E04
{
public static void main(String args[])
{
double x=1.0;
int i=0;
while(i<20)
{
System.out.println(x);
x+=0.0001;
i++;
}
}
}
*******************J03E04 Output*******************
C:\Mayank>javac J03E04.java
C:\Mayank>java J03E04
1.0
1.0001
1.0002
1.0003
1.0004
1.0005
1.0006
1.0007
1.0008
1.0009
1.001
1.0010999999999999
1.0011999999999999
1.0012999999999999
1.0013999999999998
1.0014999999999998
1.0015999999999998
1.0016999999999998
1.0017999999999998
1.0018999999999998
/* Program of J03E05 */
class J03E05
{
public static void main(String args[])
{
char ch='a';
System.out.println(ch +""+(int)ch);
ch='2';
System.out.println(ch +""+(int)ch);
ch='Z';
System.out.println(ch +""+(int)ch);
}
}
*****************J03E05 Output****************
C:\Mayank>javac J03E05.java
C:\Mayank>java J03E05
a97
250
Z90
/* Program of J03E06 */
class J03E06
{
public static void main(String args[])
{
int x;
double d;
x=5;
d=x;
System.out.println("int"+ x +"double"+ d);
d=2.95;
//x=d;
x=(int)d;
System.out.println("int"+ x +"double"+ d);
}
}
**************J03E06 Output**************
C:\Mayank>javac J03E06.java
C:\Mayank>java J03E06
int5double5.0
int2double2.95
/* Program of J03E07 */
class J03E07
{
public static void main(String args[])
{
int x;
x=65;
while(x<70)
{
System.out.println(x +""+(char)x);
x=x+1;
}
}
}
*****************J03E07 Output****************
C:\Mayank>javac J03E05.java
C:\Mayank>java J03E05
a97
250
Z90
/* Program of J03E08 */
class J03E08
{
public static void main(String args[])
{
int numChips=1;
System.out.println("Open the bag and.......");
do
{
System.out.println("can't stop.....");
numChips=numChips+1;
}while(numChips<6);
System.out.println("Can't Stop!");
}
}
*****************J03E08 Output****************
C:\Mayank>javac J03E08.java
C:\Mayank>java J03E08
Open the bag and.......
can't stop.....
can't stop.....
can't stop.....
can't stop.....
can't stop.....
Can't Stop!