Q1 Example Class To Demostrate The Shorthand Notation
This document contains code snippets demonstrating various Java programming concepts like operators, control flow statements, methods, classes, etc. Each code snippet is preceded by a question number and describes a concept through a short program. There are over 15 code snippets covering topics like arithmetic operators, relational operators, if-else statements, for loops, switch statements, method definitions and more.
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
69 views
Q1 Example Class To Demostrate The Shorthand Notation
This document contains code snippets demonstrating various Java programming concepts like operators, control flow statements, methods, classes, etc. Each code snippet is preceded by a question number and describes a concept through a short program. There are over 15 code snippets covering topics like arithmetic operators, relational operators, if-else statements, for loops, switch statements, method definitions and more.
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5
Q1 Example class to demostrate the shorthand notation
public class shorthand
{ public void work() { int a=10; float b=0; a!=10; b"=10; #$stem%out%println(&a is &!a); #$stem%out%println(&b is &!b); a'=; b(=; #$stem%out%println(&)ow a is &!a); #$stem%out%println(&)ow b is &!b); a*=10; b*=10; #$stem%out%println(&)ow a is &!(!!a)); #$stem%out%println(&)ow b is &!(!!b)); + + Q,ro-ram to implement increment and decrement operators public class ppp { public void work() { int x = ./ $ = 10; #$stem%out%println(&x = & ! x); #$stem%out%println(&$ = & ! $); #$stem%out%println(&!!x = & ! !!x); #$stem%out%println(&$!! = & ! $!!); #$stem%out%println(&x = & ! x); #$stem%out%println(&$ = & ! $); + + Q0 ,ro-ram to define a ne-ation class class )e-ation { public void work() { int x = .; #$stem%out%println(&x = & ! x); int $ = "x; #$stem%out%println(&$ = & ! $); + + Q1 2he 3rithmetic class% class 3rithmetic { public void work() { int x = 14/ $ = 5; #$stem%out%println(&x = & ! x); #$stem%out%println(&$ = & ! $); #$stem%out%println(&x ! $ = & ! (x ! $)); #$stem%out%println(&x " $ = & ! (x " $)); #$stem%out%println(&x ' $ = & ! (x ' $)); #$stem%out%println(&x ( $ = & ! (x ( $)); #$stem%out%println(&x * $ = & ! (x * $)); + + Q5 ,ro-ram to demonstrate 6itwise 7peration 8n 93:3 class 6itwise {(( ''''''';emember <""3)= / >""7; / ?""@7; '''''' public void work() { int x = 10/ $ = 1; #$stem%out%println(&x = & ! x); #$stem%out%println(&$ = & ! $); #$stem%out%println(&x < $ = & ! (x < $)); #$stem%out%println(&x > $ = & ! (x > $)); #$stem%out%println(&x ? $ = & ! (x ? $)); + + QA,ro-ram to implement relational 7perators class ;elational { public void work() { int x = 4/ $ = 11/ B = 11; #$stem%out%println(&x = & ! x); #$stem%out%println(&$ = & ! $); #$stem%out%println(&B = & ! B); #$stem%out%println(&x C $ = & ! (x C $)); #$stem%out%println(&x D B = & ! (x D B)); #$stem%out%println(&$ C= B = & ! ($ C= B)); #$stem%out%println(&x D= $ = & ! (x D= $)); #$stem%out%println(&$ == B = & ! ($ == B)); #$stem%out%println(&x E= $ = & ! (x E= B)); + + Q4 ,ro-ram to implement arithmetic on float values% class FloatGath {
public void work(){ float x = 0%5F/ $ = 4%0F; #$stem%out%println(&x = & ! x); #$stem%out%println(&$ = & ! $); #$stem%out%println(&x ! $ = & ! (x ! $)); #$stem%out%println(&x " $ = & ! (x " $)); #$stem%out%println(&x ' $ = & ! (x ' $)); #$stem%out%println(&x ( $ = & ! (x ( $)); #$stem%out%println(&x * $ = & ! (x * $)); + + Q. Example Hlass definition to demonstrate the increment operators% public class incdec { public void operation() { int a=10; int b=0; #$stem%out%println(Ia is I!(a!!)); #$stem%out%println(Ib is I!(b!!)); #$stem%out%println(I)ow a is I!a); #$stem%out%println(I)ow b is I!b); #$stem%out%println(I)ow a is I!(!!a)); #$stem%out%println(I)ow b is I!(!!b)); + + QJ Example pro-ram to demonstrate the(( usa-e of implicit or automatic t$pe conversion public class order { public void test() { b$te amount=10; float account = 1%0F; double sum = (double) (amount ' account); #$stem%out%println(I2he value of sum is I!sum); + + Q10 Example pro-ram to demostrate the usa-e of if else statement class ppp { public void demoifelse() { b$te amount=10; float account = 1%0F; if (amount==10 << accountC10) { #$stem%out%println(I2he value is I!account); + else { #$stem%out%println(I2he value is I!amount); + + + Q11 Example Hlass =efinition to demonstrate the usa-e of if else if statement class aaa { public void work() { int a=10/ b=0/ c=00; #$stem%out%println(I2he -reatest value is I); if (aDb) { if (aDc) { #$stem%out%println(a); + else { #$stem%out%println(c); + + else { if (cDb) { #$stem%out%println(c); + else { #$stem%out%println(b); + + + + Q1 ,ro-ram to input marks in five subKects and displa$ the -rade% class work { public void compute(int m1/int m/ int m0/ int m1/ int m5) { float av-/avera-e/-rade/c; av-=(m1!m!m0!m1!m5)(5; if(av-C=10) { #$stem%out%println(I-rade is cL); + if(av-C=40<<av-D=10) #$stem%out%println(I-radeis bL); if(av-D40) { #$stem%out%println(I -rade is aL); + + + Q10 Example ,ro-ram M Nsin- break and continue class ppp { public void example() { looponeM for(int i=1;iC5;i!!) { #$stem%out%println(i); if(iD=.) break; for(int k=1;kC=5;k!!) { #$stem%out%print(IOelloL!k); if (iCk) continue loopone; + + + + Q11 ,ro-ram to displa$ the followin- series 1!"0!1%%%%%%%n class math { public void series(int n) { double a/b/c; #$stem%out%println(&2he rePuired series is &); for(int i=1;iC=n;i!!) { b=Gath%pow("1/i); #$stem%out%print(& &!i'b); + + + Q15 ,ro-ram to displa$ the name of the week da$ as per the entered number class test1 {
public void work(int num) { switch(num) { case 1M #$stem%out%println(&2he da$ is Gonda$&); break; case M #$stem%out%println(&2he da$ is 2uesda$&); break; case 0M #$stem%out%println(&2he da$ is 2uesda$&); break; case 1M #$stem%out%println(&2he da$ is Qednesda$&); break; case 5M #$stem%out%println(&2he da$ is 2hursda$&); break; case AM #$stem%out%println(&2he da$ is Frida$&); break; case 4M #$stem%out%println(&2he da$ is #aturda$&); break; defaultM #$stem%out%println(&#orr$/ this da$ of the week does not exist&); + + + Q1A ,ro-ram to enter an$ number (max% 0 di-its) and check the nature of its di-its% class checkdi-it { public void compute(int a) { if(aC10) { #$stem%out%println(a!&is sin-le di-it no%&); + if(aD10 << aC100) { #$stem%out%println(a!&is double di-it no%&); + if(aD100) { #$stem%out%println(a!&is triple di-it no%&); + + +