Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Java

i

Uploaded by

Sakshi Rajmane
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Java

i

Uploaded by

Sakshi Rajmane
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

\\WAP TO MAKE THE USE OF LOGICAL OPERATORS

public class Main


{
public static void main(String[] args) {
int a=10,b=5,c=30;
if (a>=b & a>=c)
{
System.out.println("Largest="+a);

}
else if (b>=a & b>=c)
{
System.out.println("Largest="+b);

}
else if (c>=a & c>=b)
{
System.out.println("Largest="+c);
}

}
}
\\ no is even or odd
public class Main
{
public static void main(String[] args) {
int a=11;
if (a % 2== 0)
{
System.out.println("EVEN NO");

}
else if (a %2==1)
{
System.out.println("ODD NO");

}
}
\\switch case
public class Main
{
public static void main(String[] args) {
char ch;
ch='a';
switch(ch){
case 'a':
System.out.println("vowel");
break;
case 'e':
System.out.println("vowel");
break;
case 'i':
System.out.println("vowel");
break;
case '0':
System.out.println("vowel");
break;
case 'u':
System.out.println("vowel");
break;
default :
System.out.println("constant");
}
}
}
\\ pyramid using loop
public class Main
{
public static void main(String[] args) {
int row=9, i, j;
for(i=0; i<row; i++)
{
for(j=i; j<row; j++)
System.out.print("* ");
System.out.print("\n");
}

}
}
o/p:
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
\\multilevel inheritance
public class Main
{
public static void main(String[] args) {
c c1=new c();
c1.getc();
c1.getb();
c1.geta();
}
}
class a{
public void geta(){
System.out.println("geta method of class a");
}
}
class b extends a{
public void getb(){
System.out.println("getb method of class b");
}
}
class c extends b{
public void getc(){
System.out.println("getc method of class c");
}
}
\\multiple inheritance using interface
public class Main
{
public static void main(String[] args) {
finalclass f1= new finalclass();
f1.finalmethod();
f1.displaycat();
f1.bark();

}
}
class animal{
public void display(){
System.out.println("dislplay method of class animal");
}
}
interface dog {
public void bark();
}
interface cat {
public void displaycat();
}
class finalclass implements dog,cat {

public void finalmethod(){


System.out.println("finalmethod of finalclass class");
}
public void displaycat(){
System.out.println("displaycat method of cat interface");
}
public void bark(){
System.out.println("bark method of dog interface ");
}
}

You might also like