Lowercase to Uppercase, Length of Array, Character count

import java.util.Arrays;
public class Main{

     public static void main(String []args){
        char c1='s';
        String str1="rock";
        char[] str2= {'s', 't', 'a', 'r'};
        String str3=new String("star");
        String str4="star";
        System.out.println(str1+" "+str3);
        System.out.println(str1.toUpperCase()+ " "+str3.toUpperCase());
        System.out.println(Arrays.toString(str2));
        int arrLength = str2.length;
        System.out.println("The length of array is: " + arrLength);
        
        System.out.println(str1+ str1.length());
        System.out.println(str2.length);
     }
}

Output: 
rock star                                                                                                               
ROCK STAR                                                                                                               
[s, t, a, r]                                                                                                            
The length of array is: 4                                                                                               
rock4                                                                                                                   
4  

1. Max and min, 2. sum and avg, 3. search for an element, 4. move the min to the beginning

 1. Max and min, 2. sum and avg, 3. search for an element, 4. move the min to the beginning

Max= 20 Min= 2                                                   
Sum= 39 Avg= 7.8                                                 
Please Enter any value:                                          
89                                                               
[10, 2, 20, 3, 4]                                                
[2, 10, 20, 3, 4] 
import java.util.Scanner;
import java.util.Arrays;
public class Main
{
public static void main(String[] args) {
        int Arr[]= {10, 2, 20, 3, 4};
        
        int max=Arr[0], min=Arr[0];
        for(int i=0; i< Arr.length; i++) {
            if(Arr[i]> max)max=Arr[i];
            if(Arr[i]< min)min=Arr[i];
        }
        System.out.println("Max= "+max+" Min= "+min);
        
        int sum=0;
        for(int j=0; j<Arr.length; j++) {
            sum=sum+Arr[j];
        }
        double avg=(double)sum/Arr.length;
        System.out.println("Sum= "+sum+" Avg= "+avg);
        
        Scanner scn= new Scanner(System.in);
        System.out.println("Please Enter any value: ");
        int value=scn.nextInt();
        
        boolean Flag=false;
        for(int k=0; k<Arr.length; k++) {
            if(value== Arr[k]) 
                Flag=true;
            if(Flag)
                System.out.println("Not Found");
        
        System.out.println(Arrays.toString(Arr));
        int temp;
        for (int q=1; q<Arr.length; q++){
            if (Arr[q]<Arr[0]){
                temp=Arr[q];
                Arr[q]=Arr[0];
                Arr[0]=temp;
            }
        }
        System.out.println(Arrays.toString(Arr));
        }
        //System.out.println(Arrays.toString(Arr));
        
}
}

Arrays

import java.util.Scanner;
import java.util.Arrays;
public class Main
{
public static void main(String[] args) {
        int x[] = new int [10];
        
        int[] y;
        y=new int[5];
        
        x[0]=10;
        x[1]=20;
        x[9]=50;
        
        int z[]={1,2,3,4,5};
        System.out.println(Arrays.toString(x));
        //x[10,20,000,50];
        System.out.println(x[0]);
        System.out.println(x[1]);
        System.out.println(x[z.length]);
        Scanner scn= new Scanner (System.in);
        for(int i=0; i<y.length; i++)
            y[i]=scn.nextInt();
            
        for(int i=0; i<y.length; i++)
            System.out.print(y[i]+" ");
}
}
===========================


charAt, indexOf, substring, equals

 


Triangle Star

 *
**
***
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
        for(int i=1; i<=3; i++){
            for(int j=1; j<=i;j++){
                System.out.print("*");
            }
        System.out.println();
        }
}
}
==============
  *
 **
***
import java.util.Scanner;
public class Main{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      System.out.print("Enter the number of rows: ");
      int row = scan.nextInt();
      for (int i = 1; i <= row; i++){
         for (int j = row; j >= i; j--){
            System.out.print(" ");
         }
         for (int j = 1; j <= i; j++){
            System.out.print("* ");
         }
         System.out.println();
      }
   }
}



Switch Case Weekdays

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    System.out.print("Please enter any number: ");
    int num = scn.nextInt();
    switch(num) {
        case 1:
            System.out.println("It's Sunday");
            break;
        case 2:
            System.out.println("It's Monday");
            break;
        case 3:
            System.out.println("It's Tuesday");
            break;
        case 4:
            System.out.println("It's Wednesday");
            break;
        case 5:
            System.out.println("It's Thursday");
            break;
        case 6:
            System.out.println("It's Friday");
            break;
        case 7:
            System.out.println("It's Saturday");
            break;
        default:
            System.out.println("It's wrong day number");
            
    }
}
}
===============
//Nested if
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    System.out.print("Please enter any number: ");
    int num = scn.nextInt();

        if(num==1)
            System.out.println("It's Sunday");
            
        else if(num==2)
            System.out.println("It's Monday");
           
        else if(num==3)
            System.out.println("It's Tuesday");
            
        else if(num==4)
            System.out.println("It's Wednesday");
            
        else if(num==5)
            System.out.println("It's Thursday");
            
        else if(num==6)
            System.out.println("It's Friday");
            
        else if(num==7)
            System.out.println("It's Saturday");
            
        else
            System.out.println("It's wrong day number");
}
}


1+2+3+.....+10=55

 public class Main
{
public static void main(String[] args) {
    int sum=0;
    for(int i=1; i <= 10; i++) {
        sum=sum+i;
    }
    System.out.println("Sum= "+ sum);
}
}
Output: Sum= 55
===========