NPTEL Java Assignment week 8
With the growth of Information and Communication Technology, there is a need to develop large and complex software. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment.
Programming In Java Assignment 8 Answers 2022
Programming in Java is a MOOC based course which is 12 weeks in duration and can fulfill the criteria of 4 credits in a year. You can visit the NPTEL SWAYAM platform and register yourself for the course. This course is brought to you by Prof. Dr. Debasis Samanta who holds a Ph.D. in Computer Science and Engineering from the Indian Institute of Technology Kharagpur.
Programming In Java 2020 Details:-
- Who Can Join: The undergraduate students from the engineering disciplines namely CSE, IT, EE, ECE, etc. might be interested in this course.
- Requirements/Prerequsites: The course requires that the students are familiar with a programming language such as C/C++ and data structures, algorithms.
- INDUSTRY SUPPORT: All IT companies.
Java Assignment Week 8 Answers:-
Java Week 8: Q1.
Write a program which will print a pyramid of “*” ‘s of height “n” and print the number of “*” ‘s in the pyramid.
Answer/Code:-
import java.util.*;
public class Pattern1 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
// Add the necessary code in the below space
int k=0, s=0;
for(int i=1;i<=n;++i,k=0){
for(int j =1;j<=n-i;++j){
System.out.print(" ");
}
while(k !=2 *i-1){
System.out.print("* ");
s=s+1;
++k;
}
System.out.println();
}
System.out.println(s);
}
}
Java Week 8: Q2
Write a program which will print a pascal pyramid of “*” ‘s of height “l” .
Answer/Code:-
import java.util.*;
public class Pattern2 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int l = inr.nextInt();
// Add the necessary code in the below space
for(int i=0;i<l;i++)
{
for(int j=l-i; j>1; j--)
{
System.out.print(" ");
}
for(int j=0;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
Java Week 8: Q3
Write a program which will print a pyramid of “numbers” ‘s of height “n” and print the sum of all number’s in the pyramid.
Answer/code:-
import java.util.*;
public class Pattern3 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
// Add the necessary code in the below space
int i,j,k,c,t=1,s=0;
c=n-1;
for(i=1;i<=n;i++)
{
int start=1;
for(j=1;j<=c;j++)
{
System.out.print(" ");
}
for(k=1;k<=t;k++)
{
System.out.print(start+" ");
s=start+s;
start++;
}
c--;
t+=2;
System.out.print("\n");
}
System.out.println(s);
}
}
NPTEL » Programming In Java Assignment week 6 Sep-2020
Java Week 8: Q4
Write 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”.
Answer/Code:-
import java.util.*;
public class Pattern4 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int l = inr.nextInt();
// Add the necessary code in the below space
int k;
if(l%2==0)
System.out.print("Invalid line number");
else{
for(int i=0;i<l;i++){
k=0;
if(i<=l/2){
for(int j = l-i;j>l/2 + 1;j--){
System.out.print(" ");
}
while(k<(i+1)){
System.out.print("*" + " ");
k++;
}
}
else {
for(int j =l-i; j< l/2 + 1; j++)
System.out.print(" ");
while(k < (l-i)){
if(k== l-i-1)
System.out.print("*");
else{
System.out.print("*");
System.out.print(" ");
}
k++;
}
}
if(i!= l-1)
System.out.println();
}
}
}
}
Java Week 8: Q5 –
Write a program to display any digit(n) from 0-9 using “7 segment display“.
Answer/Code:-
import java.util.*;
public class Pattern5 {
public static void main(String[] args) {
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
// Add the necessary code in the below space
if(n==5){
System.out.println(" _ ");
System.out.println("|"+"_ ");
System.out.println(" _"+"|");
}
if(n==4){
System.out.println(" ");
System.out.println("|_|");
System.out.println(" |");
}
if(n==1){
System.out.println(" |");
System.out.println(" |");
}
if(n==6){
System.out.println(" _ ");
System.out.println("|_ ");
System.out.print("|_|");
}
if(n==3){
System.out.println(" _ ");
System.out.println(" _|");
System.out.print(" _|");
}
if(n==2){
System.out.println(" _ ");
System.out.println(" _|");
System.out.print("|_");
}
if(n==0)
{
System.out.println(" _ ");
System.out.println("| |");
System.out.println("|_|");
}
if(n==7)
{
System.out.println(" _ ");
System.out.println(" |");
System.out.print(" |");
}
if(n==8)
{
System.out.println(" _ ");
System.out.println("|_|");
System.out.print("|_|");
}
if(n==9)
{
System.out.println(" _ ");
System.out.println("|_|");
System.out.print(" _|");
}
}
}
Find Other Quiz Here:
Amazon Fashion Quiz Answers & Win ₹1000
Amazon Great Indian Festival Quiz Answers: Win Rs. 50,000
NPTEL » Programming In Java Assignment week 6 Sep-2020
NPTEL » Programming In Java Assignment week 7 Sep-2020
NOTE: These codes are based on our knowledge. Answers might be incorrect, we suggest you to not the copy-paste answers blindly.