WAP To Find The Sum of The Series S 1 + (3/2!) + (5/3!) + (7/4!) + ....... To N
WAP To Find The Sum of The Series S 1 + (3/2!) + (5/3!) + (7/4!) + ....... To N
WAP To Find The Sum of The Series S 1 + (3/2!) + (5/3!) + (7/4!) + ....... To N
Project work
Pg. 135 write in shoe lace file as shown with questions as comment , prg soln and variable desc.
PROGRAM 1a
/*
*WAP to find the sum of the series
*S = 1 + (3/2!) + (5/3!) + (7/4!) + ....... to n
**/
import java.util.Scanner;
int count = 0;
if (revNum == i) {
boolean isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.print(i + " ");
count++;
if (count == 10) {
System.out.println();
count = 0;
}
}
}
}
}
}
Var desc1b
2. A number is said to be Multiple Harshad number, when divided by the sum of its digits,
produces another 'Harshad Number'. Write a program to input a number and check whether it is a
Multiple Harshad Number or not.
(When a number is divisible by the sum of its digit, it is called 'Harshad Number').
Sample Input: 6804
Hint: 6804 ⇒ 6+8+0+4 = 18 ⇒ 6804/18 = 378
378 ⇒ 3+7+8= 18 ⇒ 378/18 = 21
21 ⇒ 2+1 = 3 ⇒ 21/3 = 7
Sample Output: Multiple Harshad Number
import java.util.Scanner;
a.
55555
4 4 4 4
3 3 3
2 2
1
public class Project3a
{
public void displayPattern() {
for (int i = 0; i < 5; i++) {
System.out.println();
}
}
}
Output
b.
12345
22345
33345
44445
55555
public class Project3b
{
public void displayPattern() {
for (int i = 1; i <= 5; i++) {
System.out.println();
}
}
}
4. Using the switch statement, write a menu driven program for the following:
switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;
case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;
default:
System.out.println("Incorrect Choice");
}
}
}
5. Using nested loop generate a Pascal’s Triangle
/**
* Program to generate a Pascals triangle of asterisk with the given input
*/
public class Project5
{
// Method 1
// To print upper part of the pattern
// Inner loop 1
for (n = 0; n < m; n++) {
// Printing whitespace
System.out.print(" ");
}
// Inner loop 2
for (n = m; n <= size - 1; n++)
{
// Printing star with whitespace
System.out.print("*" + " ");
}
// Method 2
// To print lower part of the pattern
private static void displayLowerPart(int size)
{
// Declaring variables for rows and columns respectively
int m, n;
// Inner loop 1
for (n = 1; n < m; n++) {
// Printing whitespace
System.out.print(" ");
}
// Inner loop 2
for (n = m; n <= size; n++) {
// Method 3
// Main driver method
public static void main(String[] args)
{
// Declaring and initializing variable to
// size of the triangle
int size = 7;
// Calling Method 1 to
// display the upper part
displayUpperPart(size);
// Calling Method 2 to
// display lower part
displayLowerPart(size);
}
}
PROJECT =5 PROGRAMS