├── CollectionExample.java ├── InterfaceExample.java ├── StudentInfo.java ├── TestingPolymorphism.java ├── Circle.java ├── Calculator.java ├── ArrayRepresentation.java ├── AbstractExample.java ├── Inheritance.java ├── Animal.java ├── LoopingExamples.java ├── Main.java ├── Functions.java ├── DayThree.java └── ConditionalStatements.java /CollectionExample.java: -------------------------------------------------------------------------------- 1 | package com.upgrad; 2 | 3 | public class CollectionExample { 4 | 5 | public static void printStudentList(String[] studentList) { 6 | for(int i=0; i < studentList.length; i++) { 7 | System.out.println(studentList[i]); 8 | } 9 | } 10 | 11 | public static void main(String[] args) { 12 | 13 | // Array containing names of 3 students 14 | String[] studentList = {"Student - 1", "Student - 2", "Student - 3"}; 15 | printStudentList(studentList); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /InterfaceExample.java: -------------------------------------------------------------------------------- 1 | package com.upgrad; 2 | 3 | interface Drawable { 4 | // An interface contains JUST abstract methods 5 | public void draw(); 6 | } 7 | 8 | class Square implements Drawable { 9 | public void display() { 10 | System.out.println("A square was created!!"); 11 | } 12 | 13 | @Override 14 | public void draw() { 15 | System.out.println("A square was drawn!!"); 16 | } 17 | } 18 | 19 | public class InterfaceExample { 20 | public static void main(String[] args) { 21 | Square square = new Square(); 22 | square.display(); 23 | square.draw(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /StudentInfo.java: -------------------------------------------------------------------------------- 1 | package com.upgrad; 2 | 3 | class Student { 4 | private String name; 5 | private int year; 6 | private int annualFees = 100000; 7 | 8 | public Student() { 9 | } 10 | 11 | public Student(String name, int year) { 12 | this.name = name; 13 | this.year = year; 14 | } 15 | 16 | public String getDetails() { 17 | return "Name " + name + " is in the year " + year; 18 | } 19 | 20 | public int computeFee() { 21 | return this.annualFees; 22 | } 23 | } 24 | 25 | class ResearchStudent extends Student { 26 | private String reserachArea; 27 | 28 | } 29 | 30 | public class StudentInfo { 31 | public static void main(String[] args) { 32 | // instance for child class 33 | 34 | ResearchStudent student1 = new ResearchStudent(); 35 | // Method of the parent class 36 | student1.computeFee(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /TestingPolymorphism.java: -------------------------------------------------------------------------------- 1 | package com.upgrad; 2 | 3 | // DYNAMIC POLYMORPHISM 4 | class ParentClass { 5 | int a = 10, b = 20; 6 | // Method 7 | public String showDetails() { 8 | return (a + ", " + b); 9 | } 10 | 11 | public void display() { 12 | System.out.println("DISPLAYING"); 13 | } 14 | } 15 | 16 | class ChildClass extends ParentClass { 17 | int x = 100, y = 200; 18 | // Method 19 | /* public String showDetails() { 20 | return (x + ", " + y); 21 | } */ 22 | 23 | // Override the showDetails method 24 | public String showDetails() { 25 | return super.showDetails() + ", " + x + ", " + y; 26 | } 27 | } 28 | 29 | public class TestingPolymorphism { 30 | public static void main(String[] args) { 31 | ChildClass child = new ChildClass(); 32 | 33 | System.out.println(child.showDetails()); 34 | child.display(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Circle.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | public class Circle { 4 | // Attribute 5 | private float radius; 6 | 7 | // Constructors | Way of initialising the data 8 | // constructor has the SAME NAME AS THAT OF THE CLASS 9 | // IT DOES NOT HAVE ANY RETURN TYPE, NOT EVEN VOID 10 | 11 | Circle(float radius) { 12 | // this.attributeName = parameterName 13 | this.radius = radius; 14 | } 15 | 16 | // Method 17 | public float calculateArea() { 18 | return 3.14f * radius * radius; 19 | } 20 | 21 | public float calculateCircumference() { 22 | return 2 * 3.14f * radius; 23 | } 24 | } 25 | 26 | class MainClass { 27 | public static void main(String[] args) { 28 | // Object - 1 29 | Circle circle1 = new Circle(10.5f); 30 | // circle1.radius = 10.5f; 31 | 32 | // Object - 2 33 | Circle circle2 = new Circle(5.55f); 34 | // circle2.radius = 5.55f; 35 | 36 | System.out.println(circle1.calculateArea()); 37 | System.out.println(circle1.calculateCircumference()); 38 | 39 | System.out.println(circle2.calculateArea()); 40 | System.out.println(circle2.calculateCircumference()); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Calculator.java: -------------------------------------------------------------------------------- 1 | package com.upgrad; 2 | 3 | public class Calculator { 4 | 5 | 6 | // Method Overloading - You can create methods in the same class 7 | // of the same name but different parameters (type / number) 8 | 9 | public int add(int a, int b) { 10 | return a + b; 11 | } 12 | 13 | public String add(String a, int b) { 14 | return "added"; 15 | } 16 | 17 | public int division(int a, int b) { 18 | return a/b; 19 | } 20 | 21 | public int add(int a, int b, int c, int d) { 22 | return a + b + c + d; 23 | } 24 | 25 | public String add(String s1, String s2) { 26 | return s1 + "---" + s2; 27 | } 28 | } 29 | 30 | class CalculatorMain { 31 | // Main method -> One main method | static 32 | public static void main(String[] args) { 33 | 34 | // Checked Exceptions - checked on compile time 35 | int[] arr = {10, 20, 30, 40}; 36 | System.out.println(arr[10]); 37 | 38 | // Object - 1 39 | Calculator c1 = new Calculator(); 40 | System.out.println(c1.add(10, 20)); // 30 41 | System.out.println(c1.add(10, 20, 30, 40)); // 100 42 | System.out.println(c1.add("Suraj", "Kumar")); // Suraj---Kumar 43 | // Unchecked Exception -> Checked on Run-time 44 | System.out.println(c1.division(10, 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ArrayRepresentation.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ArrayRepresentation { 6 | public static void main(String[] args) { 7 | // Scanner sc = new Scanner(System.in); 8 | // 9 | // // Ask user for the size of the array 10 | // System.out.print("Enter the size of the array: "); 11 | // int n = sc.nextInt(); 12 | // 13 | // // Create the array of the specified size 14 | // int[] arr = new int[n]; 15 | // 16 | // // Ask the user for the elements in the array 17 | // // arr[index] = value; 18 | // System.out.println("Enter the values of the array!"); 19 | // for(int i=0; i < n; i++) { 20 | // System.out.print("Enter the value of index " + i + " - "); 21 | // arr[i] = sc.nextInt(); 22 | // } 23 | // 24 | // // Display the array 25 | // System.out.println("\nThe elements in the array are:-"); 26 | // // arr[0], arr[1], arr[2] ... arr[n-1] 27 | // for(int i=0; i eat, sleep, walk, produce_sound, play 20 | public void eat() { 21 | System.out.println("Eating..."); 22 | } 23 | 24 | public void sleep() { 25 | System.out.println("Sleeping...."); 26 | } 27 | public void walk() { 28 | System.out.println("Walking...."); 29 | } 30 | 31 | public void play() { 32 | System.out.println("Playing"); 33 | } 34 | 35 | 36 | // CREATE REAL WORLD ENTITIES 37 | public static void main(String[] args) { 38 | // Step 1: Create an instance of the class | Creating an object 39 | // ClassName instanceName = new constructor() 40 | Animal dog = new Animal(); 41 | dog.breed = "German Shepard"; 42 | dog.color = "Black"; 43 | dog.gender = "Male"; 44 | dog.kind = "Dog"; 45 | dog.no_of_legs = 4; 46 | dog.eat(); 47 | dog.play(); 48 | dog.walk(); 49 | dog.sleep(); 50 | System.out.println("Jack is a " + dog.breed + " which is " + dog.gender + " has a color of " + dog.color ); 51 | 52 | Animal cat = new Animal(); 53 | cat.breed = "Persian Cat"; 54 | cat.color = "White"; 55 | cat.gender = "Female"; 56 | cat.kind = "Cat"; 57 | cat.no_of_legs = 4; 58 | cat.eat(); 59 | cat.play(); 60 | cat.walk(); 61 | cat.sleep(); 62 | System.out.println("Meowth is a " + cat.breed + " which is " + cat.gender + " has a color of " + cat.color); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /LoopingExamples.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | import java.util.Scanner; 4 | 5 | // LOOPS 6 | public class LoopingExamples { 7 | 8 | // Step1: Initialize the starting point 9 | // Step2: Iniatilise / Conditionalize the end point very specifically 10 | // Step3: Be specific how to transit 11 | 12 | public static void main(String[] args) { 13 | 14 | Scanner sc = new Scanner(System.in); 15 | 16 | // 1. while Loops 17 | 18 | // INFINITE LOOP using while 19 | // while(true) { 20 | // System.out.println("Arun"); 21 | // } 22 | 23 | // int index = 0; 24 | // // Conditionalize the end point | index : 0 - 10 25 | // while(index < 11) { 26 | // System.out.println(index); 27 | // // how to transit 28 | // index += 1; // index = index + 1 29 | // } 30 | 31 | // STEP1 32 | // System.out.print("Enter the value of a: "); 33 | // int a = sc.nextInt(); 34 | // System.out.print("Enter the value of b: "); 35 | // int b = sc.nextInt(); 36 | // 37 | // // STEP2 38 | // while (a < b) { 39 | // // Code 40 | // System.out.println(a + " " + b); 41 | // // Transition 42 | // a += 1; 43 | // } 44 | 45 | // DESIGN A TABLE FOR 2 46 | 47 | // int number = 2; 48 | // int product = 0; 49 | // int counter = 1; 50 | // while(counter <= 10) { 51 | // product = number * counter; 52 | // System.out.println(number + " X " + counter + " = " + product); 53 | // counter += 1; 54 | // } 55 | 56 | // 2. for loop 57 | 58 | // for(;;) | Infinite for Loop 59 | 60 | for(int i = 0; i <= 10; i += 1) { 61 | System.out.println(i); 62 | } 63 | 64 | int product = 0; 65 | for(int i=1; i<=10; i += 1) { 66 | product = 3 * i; 67 | System.out.println("3 X " + i + " = " + product); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Main.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // System.out.println("123"); 6 | // System.out.println("Arun"); 7 | // 8 | // // We can create variables -> Comment 9 | // /* This is a 10 | // multi-line comment 11 | // */ 12 | // 13 | // // 12345, "Sarthak", true/false 14 | // 15 | // // print("\n") = println() 16 | // 17 | // // decalaring & initializing your variable at a single go 18 | // int variable1 = 12345; 19 | // System.out.println(variable1); 20 | // 21 | // // declaring a variable 22 | // int variable2; 23 | // // initializing to the variable 24 | // variable2 = 34567; 25 | 26 | // Program for school management 27 | // String studentName; 28 | // int subject1, subject2, subject3, subject4, total; 29 | // 30 | // studentName = "Tim"; 31 | // subject1 = 91; 32 | // subject2 = 67; 33 | // subject3 = 75; 34 | // subject4 = 31; 35 | // 36 | // total = subject1 + subject2 + subject3 + subject4; 37 | // 38 | // // way 1 39 | // // System.out.println("The total marks of " + studentName + " is: " + (subject1+subject2+subject3+subject4) + " / 400"); 40 | // 41 | // // way -2 42 | // System.out.println("The total marks of " + studentName + " is: " + total + " / 400"); 43 | 44 | 45 | // int num1 = 10; 46 | // int num2 = 5; 47 | // 48 | // num1 = num2 + 5; // num1 = 5 + 5 = 10 49 | // num2 = num1 + 6; // num2 = 10 + 6 = 16 50 | // 51 | // float b = 0.0f; 52 | // b = (float) (num1 * 0.01); 53 | // 54 | // boolean isTrue = true; 55 | // 56 | // // Print the square of 10 and cube of 5 57 | // int squareOfTen = num1 * num1; 58 | // System.out.println("The square of num1 is: " + sqaureeOfTen); 59 | // 60 | // System.out.println("10% of num1 is: " + b); 61 | // 62 | // System.out.println("The cube of num2 is: " + (num2*num2*num2)); 63 | 64 | 65 | // Take the input from the user [ C - scanf(), C++ - cin >> ] 66 | 67 | // In order to take input from the user you have to takr help of an important Java class 68 | // called as Scanner 69 | 70 | // vvImp -> Scanner class is a part of packagae called java.util 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Functions.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Functions { 6 | // Step1: Declare the function 7 | // Step2: Define the function -> Give the logic to the function 8 | // Step3: Use the function 9 | 10 | // 1. Create a function within the same class as that of main. 11 | // Signature -> public static returnType functionName( parameter(s) ) 12 | // static 13 | // 2. Create a separate class and use the functions by creating the object. 14 | 15 | // name = sayHelloWorld, return = void 16 | public static void sayHelloWorld() { 17 | // Logic 18 | System.out.println("Hello World!!"); 19 | } 20 | 21 | // name = sayHello, return = String 22 | public static String sayHello() { 23 | return "Hello"; 24 | } 25 | 26 | // name = giveFive, return = int 27 | public static int giveFive() { 28 | return 5; 29 | } 30 | 31 | // Create a function which take a value, and calculates it square 32 | public static int calculateSquare(int number) { 33 | return number * number; 34 | } 35 | 36 | public static int calculateCube(int num) { 37 | return (num * num * num); 38 | } 39 | 40 | // Create a function which takes 2 integer values, sums them and returns the sum 41 | public static int sumNumbers(int num1, int num2) { 42 | int c = (num1 + num2); 43 | return c; 44 | } 45 | 46 | // take 2 String values, if the length of both the strings values is 5 or more return true else return false 47 | public static boolean compareStrings(String s1, String s2) { 48 | if(s1.length() >= 5 && s2.length() >= 5) { 49 | return true; 50 | } else { 51 | return false; 52 | } 53 | } 54 | 55 | public static boolean isPrime(int number) { 56 | // Logic - if a number is divisible by 1 or itself 57 | int check = 0; 58 | for(int i=1; i<=number; i++) { 59 | if(number%i == 0) { 60 | check += 1; 61 | } 62 | } 63 | if(check == 2) { 64 | return true; 65 | } else { 66 | return false; 67 | } 68 | } 69 | 70 | public static void main(String[] args) { 71 | Scanner sc = new Scanner(System.in); 72 | 73 | // HOW TO USE FUNCTIONS (inBuilt) 74 | 75 | String name = "Upgrad"; 76 | // Find out the length of the string 77 | System.out.println(name.length()); 78 | 79 | System.out.println("the Upper case is: " + name.toUpperCase()); 80 | 81 | System.out.println(name.toUpperCase().charAt(2)); 82 | 83 | // USE -> Calling the function | saying the name of the function 84 | for(int i=1; i<=3; i++) { 85 | sayHelloWorld(); 86 | } 87 | 88 | String result = sayHello(); 89 | System.out.println(result); 90 | 91 | int out = giveFive(); 92 | System.out.println(out); 93 | 94 | // Way - 1 95 | int sq = calculateSquare(10); // 100 96 | System.out.println("Square of 10 is: " + sq); 97 | 98 | // way - 2 99 | System.out.println("The square of 15 is: " + calculateSquare(15)); 100 | 101 | System.out.println("The sum of 100 and 25 is: " + sumNumbers(100, 25)); 102 | 103 | System.out.println("The comparision is: " + compareStrings("abc", "abcdefg")); 104 | 105 | // System.out.print("Enter the number you want to find the cube of - "); 106 | // int number = sc.nextInt(); 107 | // System.out.println("The cube of " + number + " is - " + calculateCube(number)); 108 | 109 | System.out.print("Enter the number you want to check for PRIME - "); 110 | int num = sc.nextInt(); 111 | System.out.println(num + " is PRIME: " + isPrime(num)); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /DayThree.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | // Step 1 4 | import java.util.Scanner; 5 | 6 | public class DayThree { 7 | 8 | public static void main(String[] args) { 9 | 10 | // How to take input from the user 11 | 12 | // Step 2: Create an instance of the Scanner class 13 | // className instaceName = new className() 14 | Scanner sc = new Scanner(System.in); 15 | 16 | // take two integer inputs, add them and display them 17 | // System.out.print("Enter the value of a: "); 18 | // int a = sc.nextInt(); 19 | // 20 | // System.out.print("Enter the value of b: "); 21 | // int b = sc.nextInt(); 22 | // int c = a + b; 23 | // 24 | // System.out.println("The sum is: " + (a+b)); 25 | 26 | // take firstName and lastName and print the full name 27 | // System.out.print("Enter the First Name: "); 28 | // String firstName = sc.next(); 29 | // 30 | // System.out.print("Enter the Last Name: "); 31 | // String lastName = sc.next(); 32 | // 33 | // String fullName = firstName + " " + lastName; 34 | // System.out.println("Your full name is: " + fullName); 35 | 36 | 37 | // TYPE CASTING 38 | // int a = 100; 39 | // int b = 14; 40 | // 41 | // // 100 / 14 42 | // // Type casting 43 | // double c = (double)a / (double)b; 44 | // 45 | // // interting part 46 | // System.out.println(a + " " + b); 47 | // 48 | // System.out.println("The division is: " + c); 49 | // 50 | // System.out.print("Arun"); 51 | // System.out.println("Hello"); 52 | // 53 | // char ch = 'a'; 54 | // int value = ch; 55 | // System.out.println("The value is: " + value); 56 | 57 | 58 | // ARRAYS 59 | 60 | // You want marks of 10 people at a same time 61 | // 1. create 10 variables and ask your user to input 62 | 63 | // creating one variable which is going to contain multiple values inside it 64 | // MULTIPLE VALUES, ALL HAVE SAME DATATYPE 65 | 66 | // Declare an array 67 | // 1. dataType[] arrayName = { values seperated by the commas } 68 | 69 | // Declared an array 70 | String[] str; // Empty array 71 | int[] values = {10, 20, 30, 40, 50}; 72 | 73 | 74 | // access the array = arrayName[index_you_want_to_access] 75 | System.out.println("The value at index 0 is: " + values[0]); 76 | System.out.println("The value at index 1 is: " + values[1]); 77 | System.out.println("The value at index 2 is: " + values[2]); 78 | System.out.println("The value at index 3 is: " + values[3]); 79 | System.out.println("The value at index 4 is: " + values[4]); 80 | 81 | // Insert a value to an array 82 | // str[0] = "Arun"; 83 | // str[1] = "Amit"; 84 | // str[2] = "Sumit"; 85 | // 86 | // System.out.println(str[0]); 87 | // System.out.println(str[1]); 88 | // System.out.println(str[2]); 89 | 90 | // 2. Decalraing an array 91 | // -> create an empty array, where i can put fixed amount of data 92 | // dataType[] arrayName = new dataType[size] 93 | 94 | // declaring an array and initializing it by telling JVM to reserve 95 | // some memory for particular size of array 96 | // int[] arr = new int[10]; 97 | // 98 | // str = new String[5]; 99 | // 100 | // System.out.println(arr[0]); 101 | // 102 | // System.out.println(str[0]); 103 | 104 | 105 | // OPERATORS -> 2 + 3 -> Arithmetic Operators [ +, -, *, / ] 106 | 107 | // 1. Logical Operator 108 | // 2. Relational Operator 109 | // 3. Conditional Operators 110 | 111 | // 1. greater than 112 | int a = 10; 113 | int b = 20; 114 | 115 | boolean check = a >= b; 116 | System.out.println(check); 117 | 118 | int[] arr = new int[10]; 119 | // [0 ... 9] 120 | System.out.println(arr[10]); 121 | 122 | // && 123 | // (condition1) && (condition2) { } 124 | // (condition1) || (condition2) { } 125 | // !(condition) { } 126 | 127 | 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /ConditionalStatements.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ConditionalStatements { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | // I'm expecting the user input to be 10 11 | // if 10 occurs, say 10 has been found! 12 | // if 10 does not occur, say try again 13 | 14 | // System.out.print("Enter the value: "); 15 | // int value = sc.nextInt(); 16 | 17 | /* 18 | * if(condition1) { what to do when condition is True } 19 | * else { what to do when condition is False } 20 | * */ 21 | 22 | // Conditional Statements 23 | // if(value == 10) { 24 | // // do something 25 | // System.out.println("10 has been found!"); 26 | // } 27 | // else { 28 | // System.out.println("Try again!!"); 29 | // } 30 | 31 | // System.out.print("Enter the new value: "); 32 | // int value1 = sc.nextInt(); 33 | // 34 | // if(value1 == 5) { 35 | // // Do something 36 | // System.out.println(" 5 was found, value changed to 10 "); 37 | // value1 = 10; 38 | // System.out.println("New value is: " + value1); 39 | // } 40 | // System.out.println("Value is: " + value1); 41 | 42 | // System.out.print("Enter the value: "); 43 | // int check = sc.nextInt(); 44 | 45 | // Range 1 : 0 to 3 -> print(range1) 46 | // Range 2 : 4 to 7 -> print(range2) 47 | // Range 3 : 8 to 10 -> print(range3) 48 | // Range 4 : 11 to 15 -> print(range4) 49 | // Range dead -> print(Dead Range) 50 | 51 | // if(check <= 3) : else if(check >=4 && check <=7) : 52 | // if(check == 0 || check == 1 || check == 2 || check == 3) { 53 | // System.out.println("Range - 1"); 54 | // } 55 | // else if(check == 4 || check == 5 || check == 6 || check == 7) { 56 | // System.out.println("Range - 2"); 57 | // } 58 | // else if(check == 8 || check == 9 || check == 10) { 59 | // System.out.println("Range - 3"); 60 | // } 61 | // else if(check == 11 || check == 12 || check == 13 || check == 14 || check == 15) { 62 | // System.out.println("Range - 4"); 63 | // } 64 | // else { 65 | // System.out.println("Dead Range Occured!"); 66 | // } 67 | // System.out.println("Code Ended!"); 68 | 69 | // System.out.print("Enter the value of a: "); 70 | // int a = sc.nextInt(); 71 | // 72 | // System.out.print("Enter the value of b: "); 73 | // int b = sc.nextInt(); 74 | 75 | // Comparing the two integer values 76 | // c1 : a > b 77 | // c2 : a < b 78 | // c3 : a = b 79 | 80 | // if(a == b) { 81 | // System.out.println("a and b has an equal value of " + a); 82 | // } else if(a > b) { 83 | // System.out.println(a + " is greater than " + b); 84 | // } else if(a < b) { 85 | // System.out.println(a + " is lesser than " + b); 86 | // } else { 87 | // System.out.println("Code Stuck!"); 88 | // } 89 | 90 | // if(a == b) { 91 | // System.out.println("a and b has an equal value of " + a); 92 | // } else if(a > b) { 93 | // System.out.println(a + " is greater than " + b); 94 | // } else { 95 | // System.out.println(a + " is lesser than " + b); 96 | // } 97 | 98 | // NESTED IF BLOCKS 99 | 100 | // Range 1 : 0 to 3 -> print(range1) 101 | // Range 2 : 4 to 7 -> print(range2) 102 | // Range 3 : 8 to 10 -> print(range3) 103 | // Range 4 : 11 to 15 -> print(range4) 104 | // Range dead -> print(Dead Range) 105 | 106 | // System.out.print("Enter a positive value: "); 107 | // int value = sc.nextInt(); 108 | // 109 | // // Check if the value is positive of not 110 | // if(value >= 0) { 111 | // if(value >= 0 && value <= 3) { 112 | // System.out.println("Range - 1"); 113 | // } 114 | // else if(value >= 4 && value <= 7) { 115 | // System.out.println("Range - 2"); 116 | // } 117 | // else if(value >= 8 && value <= 10) { 118 | // System.out.println("Range - 3"); 119 | // } 120 | // else if(value >= 11 && value <= 15) { 121 | // System.out.println("Range - 4"); 122 | // } 123 | // else { 124 | // System.out.println("Dead Range!"); 125 | // } 126 | // } else { 127 | // System.out.println("Enter a positive value..."); 128 | // } 129 | 130 | 131 | // SWITCH 132 | 133 | // number -> 1 to 7 134 | // 1 - Monday, 2 - Tuesday, 3 - Wednesday.... 135 | 136 | // System.out.print("Enter the number: "); 137 | // int number = sc.nextInt(); 138 | // 139 | // // switch(options/ choice) 140 | // switch (number) { 141 | // case 1: 142 | // System.out.println("Monday"); 143 | // break; 144 | // case 2: 145 | // System.out.println("Tuesday"); 146 | // break; 147 | // case 3: 148 | // System.out.println("Wednesday"); 149 | // break; 150 | // case 4: 151 | // System.out.println("Thursday"); 152 | // break; 153 | // case 5: 154 | // System.out.println("Friday"); 155 | // break; 156 | // case 6: 157 | // System.out.println("Saturday"); 158 | // break; 159 | // case 7: 160 | // System.out.println("Sunday"); 161 | // break; 162 | //// default: 163 | //// System.out.println("Your week might have diff no of days, I only have 7 days... SORRY!"); 164 | //// break; 165 | // } 166 | 167 | 168 | } 169 | } 170 | --------------------------------------------------------------------------------