Week 1 Solution
Week 01 : Programming Assignment 1
import java.util.Scanner;
public class W01_P1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int number = in.nextInt();
if(number>=0)
System.out.print("Positive");
else
System.out.print("Negative");
in.close();
Week 01 : Programming Assignment 2
*********************************************************************************************
import java.util.Scanner;
public class W01_P2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double radius = in.nextDouble();
double height = in.nextDouble();
double volume=Math.PI*radius*radius*height;
System.out.printf("Volume is: %.2f", volume);
in.close();
Week 01 : Programming Assignment 3
import java.util.Scanner;
public class W01_P3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int number = in.nextInt();
for(int i=1;i<number;i++)
System.out.println(number+" x "+i+" = "+(number*i));
in.close();
Week 01 : Programming Assignment 4
import java.util.Scanner;
public class W01_P4{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
System.out.println("The Quotient is = "+(x/y));
System.out.print("The Remainder is = "+(x%y));
sc.close();
}
Week 01 : Programming Assignment 5
import java.util.Scanner;
public class W01_P5 {
public static void main(String[] strings) {
double width ;
double height;
Scanner in = new Scanner(System.in);
width = in.nextDouble();
height = in.nextDouble();
double perimeter=2.0*(width+height);
double area= width*height;
System.out.printf("Perimeter is 2*(%.1f + %.1f) = %.2f\n", height, width, perimeter);
System.out.printf("Area is %.1f * %.1f = %.2f", width, height, area);
Quiz Week 01: Programming Assignment 5
1) C
2) C
3) D
4) A
5) D
6) A
7) C
8) C
9) B
10) A
Quiz Week 02: Programming Assignment 2
1) A
2) D
3) D
4) D
5) A
6) C
7) D
8) C
9) B
10) D
W02 Programming Assignments 1
*************************************************************************************
import java.util.Scanner;
public class W02_P1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read length and width of the rectangle
int length = sc.nextInt();
int width = sc.nextInt();
int area=length*width;
System.out.print("Area is: " + area);
sc.close();
}
}
W02 Programming Assignments 2
import java.util.Scanner;
public class W02_P2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read length and width of the rectangle
int length = sc.nextInt();
int width = sc.nextInt();
int perimeter = 2*(length+width);
System.out.println("Perimeter is: " + perimeter);
sc.close();
}
}
W02 Programming Assignments 3
import java.util.Scanner;
public class W02_P3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
// Read n numbers into array
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int max = arr[0]; // Assume first element is maximum
for (int i = 1; i < n; i++)
{ if(max<arr[i])
{
max=arr[i];
}
}
System.out.println("Maximum is: " + max);
sc.close();
}
}
W02 Programming Assignments 4
import java.util.Scanner;
public class W02_P4 {
// Declare a class named Rectangle
static class Rectangle {
int length;
int width;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read length and width
int l = sc.nextInt();
int w = sc.nextInt();
// Create an object of the Rectangle class
Rectangle rect = new Rectangle();
// Assign values to the object's member variables
rect.length = l;
rect.width = w;
System.out.print("Sum of length and width is: " + (rect.length+rect.width));
sc.close();
}
}
W02 Programming Assignments 5
import java.util.Scanner;
public class W02_P5 {
// Declare a separate class named Circle
static class Circle {
int radius;
Circle(int radius)
{
this.radius=radius;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read radius value from user
int r = sc.nextInt();
// Create an object of Circle class using constructor
Circle c = new Circle(r);
// Print the radius using object member
System.out.println("Radius of the circle is: " + c.radius);
sc.close();
}
}