Skip to main content

Posts

Java if else statement     If else statement is a conditional statement that executes a block of code once the condition is true otherwise  executes else block if the condition becomes false.    Syntax :             if (condition) {                   //  code to execute              } else {                      //  code to execute                   }     Example :         public class conditionalProg {                    public static void     main(String args[]) {                    /* declaration and                   ...
Recent posts
Array in java Array is a variable that can hold more than one value at a time. Declaration :    int arr[] = {elements}    or    int [] arr = {elements} Intialization :    int arr[] = {2, 4, 6, 7,}     Example :    public class arrLesson {                public static void main(String           args[]) {                // declares an array                 int arr[] = { 2, 3, 2, 9, 3 };                                 for ( int i=0; i < arr. length ;       i++)      {                      /* outputs each element                     ...

Method Overloading in Java Best Example For Biggeners and Students.

class  plus{   static   int  add( int  a, int  b) {     return  a+b; }      static   int  add( int  a, int  b, int  c)     {       return  a+b+c;    }   }   class  Overloading1 {   public   static   void  main(String[] args)    {         //access the add method with 2 param from class plus,      //pass 2 arguments and print the return value      System.out.println (plus.add( 10 , 10 ));         //access the add method with 3 param from class plus,        //pass  3 arguments and print the return value       System.out.println (plus.add( 10 , 10 , 10 ));       } }   It will produce the following results: 20 30

simple Guessing Game in JAVA

package javaguessinggame1; import java.util.*; /**  *@title Guessing  Program  * @author Herdy  */ public class JavaGuessingGame1  { //random number declaration      static Random r= new Random();     static Scanner i = new Scanner(System.in);     public static void main(String[] args)     {   //setting the variable round to 0         int round=0;         do {  //add one to variable round while it is less than 3             round++;             System. out .println( "Round: " +round); //setting the variable com and guess to choose a random number from 0-1 only                   double com=Math.floor(Math.random()*2),                guess=Math.floor(Math.random()*2);       ...