Friday, May 20, 2022

Java Programming Examples

 1. Java Syntax:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
System.out.println("suriya parithy");
}
}

2. Data types and variables:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  // type variableName = value;
  String name = "suriya";
  int myNum = 15;
  float myFloatNum = 5.99f;
  char myLetter = 'S';
  boolean myBool = true;
  
  System.out.println(name);
  System.out.println(myNum);
  System.out.println(myFloatNum);
  System.out.println(myLetter);
  System.out.println(myBool);
  }
}

3. Java Operators:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  int sum1 =100 + 200;
  int sum2 = sum1 + 300;
  int x = 4;
  int y = 6;
  System.out.println(sum1);
  System.out.println(sum2);
  System.out.println(x-y);
  System.out.println(x == y); // returns false because 4 is not equal to 6
  System.out.println(x != y); // returns true because 4 is not equal to 6
  System.out.println(x > y); 
  System.out.println(x < y);
  System.out.println(x > 3 && x < 10); // returns true because 4 is greater than 3 AND 4 is less than 10
  System.out.println(x > 3 || x < 5); // returns true because one of the conditions are true(4 is greater than 3)
  }
}

4. Java Strings:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  String name = "suriya parithy";
  System.out.println("The length of the name string is:" + name.length());
  System.out.println(name.toUpperCase()); // Outputs "SURIYA PARITHY"
  System.out.println(name.toLowerCase()); // Outputs "suriya parithy"
  }
}

5. Java Math:
package selenium;
public class Java_Examples {
  public static void main(String[] args) {
  System.out.println(Math.max(15, 20));
  System.out.println(Math.min(5, 10));
  System.out.println(Math.sqrt(64));
  }
}


No comments:

Post a Comment