Programming in java Menu

Week 1: Programming Assignment 1

Write a Java program to check if a given integer is even or odd.
Print "Odd" if odd
and "Even" if even.

 
import java.util.Scanner;
public class W01_P1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int number = in.nextInt();
        
        // Check if the number is even or odd
        if(number%2==0)
        {
        System.out.print("Even");
        }
        else
        {
        System.out.print("Odd");
         }
        in.close();
        }
        }
			 

Explanation Click here to wtach the video



Week 1: Programming Assignment 2

Write a Java program to print the area and perimeter of a rectangle.

 
import java.util.Scanner;
public class W01_P2 { 
   public static void main(String[] strings) {
       double width ;
       double height;

       Scanner in = new Scanner(System.in);
       width = in.nextDouble();
       height = in.nextDouble();
	   
	   
	   // Calculate the perimeter of the rectangle
		double perimeter=2*(height+width);

		// Calculate the area of the rectangle
		double area=height*width;
		
		
		// Print the calculated perimeter using placeholders for values
       System.out.printf("Perimeter is 2*(%.1f + %.1f) = %.2f\n", height, width, perimeter);

// Print the calculated area using placeholders for values
       System.out.printf("Area is %.1f * %.1f = %.2f", width, height, area);    
   }
}
	   
	    

Explanation Click here to wtach the video



Week 1: Programming Assignment 3

1 - Problem Statement:      

Write a Java program to calculate the volume of a cylinder given its radius and height.

Formula:

V = π x r^2 x h
 
import java.util.Scanner;
public class W01_P3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double radius = in.nextDouble();
        double height = in.nextDouble();
		
		// Calculate the volume
	double volume=Math.PI*Math.pow(radius,2)*height;
	
	// Display the result
    System.out.printf("Volume is: %.2f", volume);
    in.close();
  }
}	   
	    

Explanation Click here to wtach the video



Week 1: Programming Assignment 4

Write a Java program to print the multiplication table of a given number up to 4.

 
import java.util.Scanner;
public class W01_P4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int number = in.nextInt();
		
		
		// Print the multiplication table of number up to 5
	int i;
	for(i=1;i<4;i++)
	{
	System.out.println(number+" x "+i+" = "+(number*i));
	}
	System.out.print(number+" x "+i+" = "+(number*i));
	
	
	in.close();
    }
}
		 

Explanation Click here to wtach the video



Week 1: Programming Assignment 5

Complete the code fragment that reads two integer inputs from keyboard and compute the quotient and remainder.
 
		import java.util.Scanner;
public class W01_P5{
       public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   int x=sc.nextInt();
	   int y=sc.nextInt();
	   
	   
	   //code for quotient and remainder

		// Uncomment and Complete this code below or create your own using the same variables
		int quotient=x/y;
		int remainder=x%y;
		
		
		System.out.println("The Quotient is = " + quotient); 
        System.out.println("The Remainder is = " + remainder);    
sc.close();  
  }
}

		
	   
	   

Explanation Click here to wtach the video



Previous :Week 1 - Assignment Next :Week 2 - Assignment