Posts

Showing posts from June, 2022

Wap to Use Increment And Decrement Operator In Java

 class iandc { public static void main(String[] arg) { int n=10; System.out.println("Before any Opertaion n="+n); System.out.println("After post increment n="+n++); System.out.println("After Pre increment n="+ ++n); System.out.println("After post Decrement n="+n--); System.out.println("After pre decrement n="+ --n); } }

Wap to use Ternary Operator in Java

 import java.util.Scanner; class Ternary { public static void main(String []arg) { Scanner scanner = new Scanner(System.in); int feb; System.out.print("Enter the no of days in February month:"); feb =scanner.nextInt(); System.out.println((feb==28) ? "The is a Leap Year" : "This is not a Leap Year"); } }

Wap to use Relational Operator in Java

 class Relational { public static void main (String []arg) { int a=10,b=20; System.out.println("Variable a="+a+"and b="+b); System.out.println("The Below statement(a==b) is false"); System.out.println(a==b); System.out.println("The Below statement(a!=b) is false"); System.out.println(a!=b); System.out.println("The Below statement(a>b) is false"); System.out.println(a>b); System.out.println("The Below statement(a<b) is false"); System.out.println(a<b); System.out.println("The Below statement(a<=b) is false"); System.out.println(a<=b); System.out.println("The Below statement(a>=b) is false"); System.out.println(a>=b); } }

Wap to use Loops in Java

 import java.util.Scanner;   class Loops   {   public static void main(String[] arg)   {      Scanner scanner= new Scanner(System.in);   int i;   System.out.print("Enter the Range upto:");   int n = scanner.nextInt();      System.out.println("This is a for loop:");   for(i=0; i<=n; i++)   {   System.out.print(i+"\t");   }   System.out.println(" ");      System.out.println("This is a While loop:");   i=n;   while(i!=0)   {   System.out.print(i+"\t");   i--;   }   System.out.println(" ");      System.out.println("This is a Do While Loop:");   i=0;   do   {   System.out.println(i+"\t");   i=i+2;   }   while(i<=n);   }   }      

WAP to use Logical Operator Java

 import java.util.Scanner; class Logical1 { public static void main(String[] arg) { Scanner scanner=new Scanner(System.in); int n1,n2,n3; System.out.print("Enter First Number:"); n1=scanner.nextInt(); System.out.print("Enter second Number:"); n2=scanner.nextInt(); System.out.print("Enter Third Number:"); n3=scanner.nextInt(); if(n1>n2 && n2>n3) { System.out.println("The && Logical operators Statement is true:"); System.out.println("First Number is Greater than two numbers:"+ n1); } if(n1>n2 || n2>n3) { System.out.println("The || Logical operators Statement is also true:"); } if(n1==n2) { System.out.println("The == Logical operators Statement is also true:"); } if(n1!=n2) { System.out.println("The ! Logical operators Statement is also true:"); } } }

WAP to use Assignment Operator in Java

 class Assignment { public static void main(String []arg) { int a=10; int n; System.out.println("Initial value of 'a' is: "+a); //=Assignment Operator n=a; System.out.println("a value is assignment to n using =operator: "+n); n+=a; System.out.println("n using+=operator:"+n); n-=a; System.out.println("n using-=operator:"+n); n*=a; System.out.println("n using*=operator:"+n); n/=a; System.out.println("n using/=operator:"+n); n%=a; System.out.println("n using%=operator:"+n); } }