What is Programming in Java?
Java is a popular object-oriented programming language that was first released in 1995. It is used for developing a wide range of applications, including desktop applications, mobile applications, web applications, and enterprise applications.
Here are some key features and concepts of Java programming:
Object-oriented programming: Java is an object-oriented language, which means that it focuses on the creation of objects that contain both data and methods that operate on that data.
Platform independence: Java programs can run on any platform that supports a Java Virtual Machine (JVM), which makes it a popular choice for cross-platform development.
Memory management: Java uses automatic memory management through a garbage collector, which helps to prevent memory leaks and makes it easier to write memory-safe code.
Exception handling: Java has a built-in mechanism for handling runtime errors or exceptions, which helps to ensure that programs can recover gracefully from unexpected errors.
Multi-threading: Java supports multi-threading, which allows programs to execute multiple threads of execution simultaneously, making it well-suited for developing concurrent applications.
Standard libraries: Java provides a large number of standard libraries that developers can use to build applications more quickly and easily, including libraries for networking, database access, and user interface development.
To get started with Java programming, you will need to install the Java Development Kit (JDK) on your computer. Once you have installed the JDK, you can use an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA to write and debug your code.
To learn Java programming, you can start with the basics of the language, such as data types, control structures, and object-oriented programming concepts. There are many online resources and tutorials available for learning Java, including Oracle's official Java tutorials, which cover everything from the basics to advanced topics like concurrency and networking.
Week 8 : Programming Assignment 1
Due on 2023-03-23, 23:59 ISTWrite a program which will print a pyramid of "*" 's of height "n" and print the number of "*" 's in the pyramid.
For example:
Input : 5Output:
* * * * * * * * * * * * * * * * * * * * * * * * * 25
Solution :
import java.util.*;
public class Pattern1 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
int k = 0,sum=0;
for(int i = 1; i <= n; ++i, k = 0) {
for(int space = 1; space <= n - i; ++space) {
System.out.print(" ");
}
while(k != 2 * i - 1) {
System.out.print("* ");
sum=sum+1;
++k;
}
System.out.println();
}
System.out.println(sum);
}
}
Solution :
import java.util.*;
public class Pattern1 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
int k = 0,sum=0;
for(int i = 1; i <= n; ++i, k = 0) {
for(int space = 1; space <= n - i; ++space) {
System.out.print(" ");
}
while(k != 2 * i - 1) {
System.out.print("* ");
sum=sum+1;
++k;
}
System.out.println();
}
System.out.println(sum);
}
} |
Week 8 : Programming Assignment 2
Due on 2023-03-23, 23:59 ISTWrite a program which will print a pascal pyramid of "*" 's of height "l" .
For example:
input: 8
output : * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Solution :
import java.util.*;
public class Pattern2 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int l = inr.nextInt();
int i,j;
int space=l-1;
/*run loop (parent loop) till number of rows*/
for(i=0;i< l;i++)
{
/*loop for initially space, before star printing*/
for(j=0;j< space;j++)
{
System.out.print(" ");
}
for(j=0;j<=i;j++)
{
System.out.print("* ");
}
System.out.print("\n");
space--; /* decrement one space after one row*/
}
}
}
Solution :
import java.util.*;
public class Pattern2 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int l = inr.nextInt();
int i,j;
int space=l-1;
/*run loop (parent loop) till number of rows*/
for(i=0;i< l;i++)
{
/*loop for initially space, before star printing*/
for(j=0;j< space;j++)
{
System.out.print(" ");
}
for(j=0;j<=i;j++)
{
System.out.print("* ");
}
System.out.print("\n");
space--; /* decrement one space after one row*/
}
}
} |
Week 8 : Programming Assignment 3
Due on 2023-03-23, 23:59 ISTWrite a program which will print a pyramid of "numbers" 's of height "n" and print the sum of all number's in the pyramid.
For example:
input: 5
output: 1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9 95
Solution :
import java.util.*;
public class Pattern3 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
int k = 1,sum=0;
for(int i = 1; i <= n; ++i, k = 1) {
for(int space = 1; space <= n-i; ++space) {
System.out.print(" ");
}
while(k <= 2 * i - 1) {
System.out.print(k+" ");
sum=sum+k;
++k;
}
System.out.println();
}
System.out.println(sum);
}
}
Solution :
import java.util.*;
public class Pattern3 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
int k = 1,sum=0;
for(int i = 1; i <= n; ++i, k = 1) {
for(int space = 1; space <= n-i; ++space) {
System.out.print(" ");
}
while(k <= 2 * i - 1) {
System.out.print(k+" ");
sum=sum+k;
++k;
}
System.out.println();
}
System.out.println(sum);
}
} |
Week 8 : Programming Assignment 4
Due on 2023-03-23, 23:59 ISTWrite a program to print symmetric Pascal's triangle of "*" 's of height "l" of odd length . If input "l" is even then your program will print "Invalid line number".
For example:
input : 5output: * * ** * * * * *input : 6
output:
Invalid line number
Solution :
import java.util.*;
public class Pattern4 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int l = inr.nextInt();
int ul=0; // Upper Line
int ll=0; // Lower Line
// Check whether line number is odd
if (l%2!=0){
ul=(l/2)+1;
ll=l-ul;
//Code for upper half
for(int i=1;i<=ul; i++){
//Space management
for(int s=1;s<=(ul-i); s++){
System.out.print(" ");
}
// Star management
for(int j=1;j<=i; j++){
System.out.print("* ");
}
System.out.println();
}
//Code for lower half
int llc=ll;
for(int i=1;i<=ll; i++){
//Space management
for(int s=llc;s<ll; s++){
System.out.print(" ");
}
// Star management
for(int j=1;j-1<=ll-i; j++){
System.out.print(" *");
}
llc--;
System.out.println();
}
}
else{
System.out.print("Invalid line number");
}
}
}
Solution :
import java.util.*;
public class Pattern4 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int l = inr.nextInt();
int ul=0; // Upper Line
int ll=0; // Lower Line
// Check whether line number is odd
if (l%2!=0){
ul=(l/2)+1;
ll=l-ul;
//Code for upper half
for(int i=1;i<=ul; i++){
//Space management
for(int s=1;s<=(ul-i); s++){
System.out.print(" ");
}
// Star management
for(int j=1;j<=i; j++){
System.out.print("* ");
}
System.out.println();
}
//Code for lower half
int llc=ll;
for(int i=1;i<=ll; i++){
//Space management
for(int s=llc;s<ll; s++){
System.out.print(" ");
}
// Star management
for(int j=1;j-1<=ll-i; j++){
System.out.print(" *");
}
llc--;
System.out.println();
}
}
else{
System.out.print("Invalid line number");
}
}
} |
Week 8 : Programming Assignment 5
Solution :
import java.util.*;
public class Pattern5 {
private static final Map<Integer, Integer> encodings =
new HashMap<Integer, Integer>();
static {
encodings.put(0, 0x7E);
encodings.put(1, 0x30);
encodings.put(2, 0x6D);
encodings.put(3, 0x79);
encodings.put(4, 0x33);
encodings.put(5, 0x5B);
encodings.put(6, 0x5F);
encodings.put(7, 0x70);
encodings.put(8, 0x7F);
encodings.put(9, 0x7B);
}
public static void printDigit(int digit) {
int code = encode(digit);
char[] bits =
String.format("%7s", Integer.toBinaryString(code))
.replace(' ', '0').toCharArray();
lightSegment(bits[0] == '1', " _ \n", " \n");
lightSegment(bits[5] == '1', "|", " ");
lightSegment(bits[6] == '1', "_", " ");
lightSegment(bits[1] == '1', "|\n", " \n");
lightSegment(bits[4] == '1', "|", " ");
lightSegment(bits[3] == '1', "_", " ");
lightSegment(bits[2] == '1', "|\n", " \n");
}
private static void lightSegment(boolean on, String onValue, String offValue) {
System.out.print(on ? onValue : offValue);
try {
Thread.sleep(0);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
private static int encode(int digit) {
return encodings.containsKey(digit) ? encodings.get(digit) : 0x00;
}
public static void main(String[] args) throws Exception {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
printDigit(n);
}
} |
CRITERIA TO GET A CERTIFICATE
Average assignment score = 25% of the average of the best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND THE EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.
| Programming in JAVA | Answers |
| Assignment 1 | Click Here |
| Assignment 2 | Click Here |
| Assignment 3 | Click Here |
| Assignment 4 | Click Here |
| Assignment 5 | Click Here |
| Assignment 6 | Click Here |
| Assignment 7 | Click Here |
| Assignment 8 | Click Here |
| Assignment 9 | NA |
| Assignment 10 | NA |
| Assignment 11 | NA |
| Assignment 12 | NA |
Comments
Post a Comment