0 ratings 0% found this document useful (0 votes) 2 views 24 pages Java Outputs
The document contains various Java code snippets demonstrating different programming concepts such as data types, constructors, classes, inheritance, interfaces, and basic input/output operations. Each code snippet is followed by its output, indicating successful execution. The examples illustrate the use of Java syntax and structure in practical applications.
AI-enhanced title and description
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save java outputs For Later
5 enoole - 05 _ =©eoeABMaw se
Js
suv Comper
[Link] a © share
1/1 Online Java Compiler
2/1 Use this editor to write, compile and run you
3- class javaexanple {
Java code
4- public static void main¢stringl} args) {
5 byte b= 100;
6 Short s = 200:
7 int num = 1331313131;
8 long 1 = 516515351;
9 double num = 22.4: 4
10 float numa = 22.41;
n
2 [Link]¢b);
13 [Link](s);
14 [Link]. printIn(nun)
15 System. out.print1n(1):
16 system, out printIn¢numt ):
7 [Link]..printIn(num2);
18
9 ,
2}
EE ear a Cie ee fosramis =
Output
100
200
1331313131
516515351
22.4
22.4
Code fxecut ion Successfulmix Orie Javea Compiler
Main java, £
7 Output
1/7 Online sava Compiler
J 1f Satine Sova comps raju 1312347602355,
3 St IMS editor to write, compile and run your Jove code ontane john 23427 62 12
3 jomn 23822 6212 as,
4+ class Student (
5 String name: aructen seeeseh
6 Int regno,
7 int marks} marks2, marks?
8
9 HPeloult construct
10 Student() {
" name = “raju
12 regno — 131234760
3 marks! = 23.
14 marks? = 55
15 marks? ~ 100:
6 )
7
6 /parameter ized constructor
19- Student(Steing n, int ¢, int mi int m2, int m3) (
20 name —
a regno =r
22 marks? = at
2B marks? ~ m2
24 marks} — m3
25 d
26Main jova
23 marks? = m2.
24 marks} — m3
25 )
6
27 /eopy constructor
28- Student (Student s)
29 ame = [Link]
30 regno —[Link].
u markst — [Link]
32 marks? ~ [Link]?
3 marks3 ~ s.marks3.
3a ,
35
36+ void display() ¢
37 [Link](name - "\t" + regno + “\t
Ver + maeks3)
38 )
399)
40
+ public class Main {
| tA pli static void msntstring args) 4
Student st = new Student
45 Student s3 = new Student(s2);
46
42 et dientaw
marks! +
45)
\t
john 23422 6212
marks?[Link]
35
36
”
38
39
40
4
42
43
4a
45
46
47
48
49
50
51
92
53
54
56
7
58
59
void displayc) { Fayu 131234700
[Link](name + “\t Jono 2322 G21
S eRMO "Nt + marks) + "VL + marks;
"\t" + marks3) VNU + marks john 23422 6217 as
,
} Code Executs
public class Main {
Public static void main(String{} args) (
Student st - new Student()
Student 52 = new Student("john”, 23422, 62, 12, 45)
Student s3 - new Student(s2)
[Link]():
[Link]():
[Link]():
WO1 // Online Java Compiler
2 // Use this editor to write, compile and run your Java code online
3
4 public class WrapperExample1
5.4
6 public static void main(string(] args)
7 {
8 int a 20:
9 Integer i = Integer .valueOf(a);
10 Integer j = a:
" [Link] .printIn(ar""sir"" 5):
12 ,
134
14
15
16
7
18
19
20
ra)
Output
202020
CodeMain,java
sre EE oon
2 // Use this editor to writ oP prac tea gt
kprcatl am
A
public class WeapperExample2
5 1 warning
6 public static void main(stringl) args) 33
7 {
8 Integer a = new Integer(3): ie EEN TBA SHECESSTU!
9 int i> [Link]()
10 int ja.
Integer a
[Link](ar®™+is°"9)
9Online Java Compiler
[Link]
3
ae
5
6
2a.
compite ana run your Java coae ontine
import [Link];
Public class Main {
Public static void main(stringt) args) {
Scanner sc- new Scanner(systen. in):
[Link](“Enter ave
100)::"):
int average — [Link]():
char grade:
rage of your marks(less than
if Caverage>-80){
grade 'A":
Jelse if(average>-60ssaverage<80) {
grade “8
2
else if(average>-40&saverage<60) {
grade = 'C":
Y
else{
grade - °D';
,
switch(grade) {
Output
Enter average of your marks(less than 100)
2
Your passed
Better try again
Your grade iD
Code Execution Successful ==Moinjava
2
22
23
24-
2%
26
7
28
29
30
31
32
3
34
35,
36
37
38
39
40
a
a2}
a3
44
Owe
«2 Shore
grade - -p
switch(grade) {
case"A
[Link] printIn(“Excel lent
break:
case'B
[Link] printin¢“well done")
break;
case'o.
[Link]("Your passed”)
case'F
[Link]("Better try again”)
break;
default
[Link](“Inval id grade”);
,
[Link]("Your grade i*»grade):
BBQ sooner
Enter average of your marks(less than 100)
22
Your passed
Better try again
Your grade iD
Code Execution Successful =
wWeé€eu€[Link]
shoe EE ovtout
1 e Java Compiler 210% Meganadhanmega@gmai | .com5000.0
2/7 Use this editor to write. compile and run your Java code online
; ade Execution Successt uy
4= class Account {
8 private long ace_no
6 private String [Link]
7 private float amount;
8
9+ public long getacc_no(y ¢
10 return acc_no:
n )
2
13+ public void setAcc no(long ace no) ¢
4 this.acc_no = acc_no:
15 ,
16
17+ public String gettiamec) ¢
18 return name:
19 )
20- public void setNane(String name) (
” [Link] — ane:
2 ,
2B
24
public Strang getfmail() ¢
5 return email:[Link]
xf Share Ea Output
23
2101 Meganadhannegasigmai .comS000.0
24. public String getémail() ¢ “
25
return email;
26 )
27
28-
recution Successful
public void setfmail(String email) {
29 [Link] = email
30 7
3 I
32 public float getamount() {
33 return amount
4 )
35
36- public void setAmount( float amount) (
” this amount — amount
38 >
39}
40
41+ public class Main
42+ public static void main(stringl] args) 4
43 Account ace ~ new Account();
44
45 ace setAce_no(21017)
46 acc..setName(“Meganadhan”);
a7 acc. setfmail(mega@[Link]")
awe
BE sear
Host earS Shore
41- public class Main {
a2 Public static void main(String{} args) {
43 Account acc = new Account():
4a
45 acc. setAce_no(21017):
46 acc. setName(“Meganadhan" )
47 acc. setémail(“mega@gmail com”)
48, ace. setAmount (5000):
49
50- [Link] Ing
st ace.getacc_no()+""»
52 acc. getName )+
53 ace. getémail()+""+
54 ace. getAmount()
55. )
56 »
sy}
sa
59
60
6
62
Output
2101 7Meganadhanmegaagmai | .cons000.0
Code Execution SuccessfulMain jove ; < soo EEE
1
2
1
4
5
6
8
9
10
n
”
RB
15
Online Java Compiter
Use this editor to write, compile and run your Java code onlin
import [Link] Seanner
+ class Main {
public static void maan(steinel] ares) «
char operator
Double number nunber2,result
Scanner input -new Scanner ([Link])
[Link] printin(~Choose an operator:+,-.*.0r/"),
operator ~ input next ()-charAt(0)
[Link]("Enter first number")
number? = input nextDouble()
[Link](“Enter Second number”):
number? — input nextDouble()
smitch(operator) {
case’
result -nunbert-nunber2
[Link] print In(numbert=*+“vnumber2+"="sresult)
break:
Hoos
Output
Choose an operator +.-.*.0r/
Enter first number
56
Enter Second nunber
a
$96.023.0-1288.0,[Link]
26
27
28
29
30
a
32
33
34
35
36
37
38
39
40
a
42
43
44
45
46
47 ,
4B)
49
50
3 Shore Ea Output
break Choose an operator +
Enter first number
56
Enter Second number
23
56.0423.0-1288.0
case
Fesult=nunber1 number? :
[Link](nunbert+*.*snunber2:"<"-result);
break;
case"**
Fesult=number 1 *number2;
System. out print In(numberts** snunber2+"="+result):
=== Code Execution Successty
break
case's
resul t-numbert /number2:
System. out .printIn(numbert+"/" snunber2-
break: |
sresult):
default
[Link]("Invalid operator!*).
}
input..close();[Link] [2G & Shore En Output
1/7 Online Java Compiler 10
& 2 // Use this editor to write. compile and run your Java code online 20
e 30
zg 4> class Main { 40
5+ public static void main(String{] args) ¢ 50
6 int a{] - new int{s}:
7 a0] - 10; == Code Execution Successful
% 8g alt] = 20;
E 9 a2] = 30;
10 a[3] - 40:
gE ou af4] = 50:
2
e 2B for(int i-0;i<[Link];ir+)
14 [Link](afi}):
15 }
1e }
ei AT
> 18
19
s- 20
2a
22[Link] 2 “6 shore ER output
1/7 Online Java Conpi ler tating
2 1/ Use this editor to write, compile and run your Java code online rking..
3
4 class Animal { code
5+ woid eat() ¢
6 [Link] .printin(“Fating. ..");
? ,
a>
9
10+ class Dog extends Animal {
11+ void bark() {
12 [Link](“Barking...");
13 ,
1a)
15
16- public class Main {
17- public static void main(String) args) {
18 Dog d — new Dog):
19 [Link]();
20 [Link]();
2 y
2}
23
24
txecution Stecess(ulk
oS
®
®
Ts
bramguvu & Share Ee Output
1 // Online Java Compiler 210.0
2 (7 Use this editor to write, compile and run your Java code online | 3.142857142857148
4> interface Shape { I == Code Execution Successful
5 Double calculatearea():
6}
7
8- class Rectangle implements Shape { 1
9 Double length; f
10 Double width;
u
12+ public Double calculatearea() { f
B return Length*width;
4 }
15 +
16
17+ class Circle implements Shape {
18 Double radius;
19
20- public Double calculateArea() {
21 return(22.0/7)*radius*radius;
2 }
23 >
24
25- class AreaCalculator {
26 public Double calculateShapeArea(Shape shape) {23} 210.0
24
3.142857142857143
25- class AreaCalculator {
26- public Double calculateShapeArea(Shape shape) {
2 return [Link]();
28 }
29
30
ue
32- public static void main(Stringt] args) {
33 Rectangle r = new Rectangle()
relength = 10.5;
width = 20.0;
Code Execution Successful
public class Main {
AreaCalculator a = new AreaCalculator();
38 ‘[Link] .printIn([Link](r)):
39
Circle ¢ = new CircleQ: |
[Link] = 1.0;
[Link] .println([Link](c)):cs
» © @®@@OABMa uw 5 a
Online Java Compiler
[Link] £2 Go Shore Ec Output
1 // Online Java Compiler dog is eating.
2 // Use this editor to write, compile and run your Java code online
Code Execution Successful
3
4 class Dog
5.
6 private void eat()
7
8 [Link](“dog is eating...");
9}
10 b&
11 public static void main(String] args)
12- {
13 Dog d1 = new Dog();
14 dt-eat();
15 3
16 }
17
18
19
20
21a %
it
R @
® © ®
Js
[Link] GS shore EBB ourour
1/7 Online Java Compiler Eating
2 11 Use this editor to write. compile and run your Java cote online | Barking
3
4+ class Animal { Code Execution Successful
5: void eat() {
6 [Link] .printIn¢*tating..."); &
? }
a}
3 |
10 class Dog extends Animal ( !
We void bark() {
12 [Link] print In¢“Barking. ..")
13 d =
wy : |
15
16+ public class Main { !
7. public static void main(String[} args) { "
18 Dog d = new Dog():
19 [Link]();
20 [Link]():
a }
22 4}
23
24
25
a aii ns wen BOUEE[Link] TD 1&8 share Ee Output
// Online Java Compiler Hello
// Use this editor to write. compile and run your Java code online
I Code Execution Successtul
> public class Main {
+ interface Printable {
void print();
10 static class A implements
11+ Printable {
12- public void print() {
13
4 [Link] .printIn( “Hel lo”):
15 }
16}
7
18- public static void main(Stringl] args) 4
19 ‘A obj ~ new AQ:
20 [Link]():
a >
22 4
23
24
> © @®@CMABan 5 «
1S.
oe= Mainjave £3. tq! eG share Ea Output
R
1 // Online Java Compiler running safely
2 1/ Use this editor to write. compile and run your Java code online
3 Code Fxecution Successful
s 4+ abstract class Bike {
5 abstract void run();
Bs)
7
a public class Main extends Bike {
9 ]
10- public void run() { i
1 System. out .printIn(“running safely") |
12 }
3B
14. public static void main(String{] args) { |
15 Bike obj - new Main(): |
16 [Link](); |
7 } |
Sow ) |
19 |
is 20 ]
2
22 |)
wy
ta
@
® ®
®
so
woevanneuns
10
YW
12
13
14-
15-
16
7
18
19
20-
at.
22
23
24
// Online Java Compiler
‘7 Use this editor to write, compile and run your Java code online
abstract class Bank {
abstract int getRateOfInterest():
class SBI extends Bank {
int getRateOfInterest() {
return 7;
class PNB extends Bank {
int getRateOfInterest() {
return 8:
public class Main {
public static void main(Stringl] args) {
Bank b;
b = new SBI():
darvbate af interest is:"+b
Output
Rate of interest is: 7%
Rate of interest is:8%
Code Execution Successful