SIMPLE PROGRAMS
SIMPLE PROGRAMS
// 2. variables
public class Simple{
public static void main(String[] args){
int a=10;
float f=23.7f;
System.out.println(a);
System.out.println(f);
}}
// 3. unary operators
public class OperatorExample{
public static void main(String args[]){
int x=10;
System.out.println(x++);//10 (11)
System.out.println(++x);//12
System.out.println(x--);//12 (11)
System.out.println(--x);//10
}}
// 4. arithmatic operators
// 5. if statement
public class Student {
public static void main(String[] args) {
int x = 10;
int y = 12;
if(x+y > 20) {
System.out.println("x + y is greater than 20");
}
}
}
// 6. if else
public class Student {
public static void main(String[] args) {
int x = 10;
int y = 12;
if(x+y < 10) {
System.out.println("x + y is less than 10");
} else {
System.out.println("x + y is greater than 20");
}
}
}
// 7. if else ladder
public class Student {
public static void main(String[] args) {
String city = "Delhi";
if(city == "Meerut") {
System.out.println("city is meerut");
}else if (city == "Noida") {
System.out.println("city is noida");
}else if(city == "Agra") {
System.out.println("city is agra");
}else {
System.out.println(city);
}
}
}
//8. switch
public class Student {
public static void main(String[] args) {
int num = 2;
switch (num){
case 0:
System.out.println("number is 0");
break;
case 1:
System.out.println("number is 1");
break;
default:
System.out.println(num);
}
}
}
// 9. while loop
public class Calculation {
public static void main(String[] args) {
int i = 0;
System.out.println("Printing the list of first 10 even numbers \n");
while(i<=10) {
System.out.println(i);
i = i + 2;
}
}
}
class Multiply {
public static void main(String[] args)
{
// f is to ensures that numbers are float DATA TYPE
float f1 = 1.5f;
float f2 = 2.0f;
class Swap {
public static void main(String[] args)
{
// Random integer values
int m = 9, n = 5;
// Main class
class OddEven {
else