Skip to main content

Posts

Showing posts from September, 2021

Even_odd.java #Program to find Odd and Even

// Write a program to print whether a number is even or odd, also take input. import   java . util . Scanner ; public   class   Odd_Even  {      public   static   void   main ( String []  args ) {                   Scanner   in  =  new   Scanner ( System . in );          System . out . print ( "Enter the number to check even or odd :" );          int   num  =  in . nextInt ();          if  ( num  %  2  == 0 ) {              System . out . println ( num +  " is an even num...

Program to Print the table of the Number

// Take a number as input and print the multiplication table for it. import   java . util . Scanner ; public   class   Table  {      public   static   void   main ( String []  args ) {          Scanner   in  =  new   Scanner ( System . in );          System . out . print ( "Enter a number to multiply and get the table : " );          int   num  =  in . nextInt ();          for  ( int   i  =  1 ;  i  <= 10 ;  i ++) {              System . out . println ( num +  " x "  + i +  "= "  +( i * n...

Leap year Program in Java

import   java . util . Scanner ; // Input a year and find whether it is a leap year or not. public   class   Leap_year {      public   static   void   main ( String []  args ) {                   Scanner   in  =  new   Scanner ( System . in );          System . out . print ( "Please enter a year : " );          int   year  =  in . nextInt ();                   boolean   ans  =  checkyear ( year );          if  ( ans  ==  true ) {            ...

16.Conditional Statements in Java (If , If-else , else- if )

                                                           CONDITIONAL STATEMENTS A conditional statement  consists of a condition and a task . When the condition is true, the application performs the task. The condition portion of a conditional statement is also called an expression. There are four types of conditional statements in java :  If Condition. If else condition. If else If condition. Nested If condition. If condition :  The Java if statement tests the condition. It executes the  if block  if condition is true. if (condition){   //code to be executed    }   If else Condition :  The  Java   if statement  is used to test the condition. It checks  boolean  condition:  true  or  false . There ar...