0% found this document useful (0 votes)
2 views22 pages

Icse Class 9 Java Programs

The document contains a comprehensive collection of 60 Java programs designed for ICSE Class 9 Computer Applications, organized into four levels covering basic output, user input, math library methods, and conditional statements. Each program includes code snippets demonstrating various programming concepts such as variable handling, arithmetic operations, and control structures. Prepared by Rahul Kumar Lal, it serves as a practical guide for students to enhance their Java programming skills in a structured manner.

Uploaded by

rishisah19901990
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views22 pages

Icse Class 9 Java Programs

The document contains a comprehensive collection of 60 Java programs designed for ICSE Class 9 Computer Applications, organized into four levels covering basic output, user input, math library methods, and conditional statements. Each program includes code snippets demonstrating various programming concepts such as variable handling, arithmetic operations, and control structures. Prepared by Rahul Kumar Lal, it serves as a practical guide for students to enhance their Java programming skills in a structured manner.

Uploaded by

rishisah19901990
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ICSE CLASS 9 COMPUTER APPLICATIONS

60 Comprehensive Java Programs & Solutions (BlueJ Environment)

Prepared by: Rahul Kumar Lal

LEVEL 1: BASIC OUTPUT & VARIABLES (PROGRAMS 1 – 10)

Prog 1 Print Personal Details

public class Program1 {


public static void main(String[] args) {
[Link]("Name: Rahul Sharma");
[Link]("Class: 9 | Section: A");
[Link]("School: St. Xavier's School");
}
}

Prog 2 Print Escape Sequences

public class Program2 {


public static void main(String[] args) {
[Link]("Hello\tWorld!"); // Tab space
[Link]("Line 1\nLine 2"); // New line
[Link]("\"ICSE Java Programming\""); // Double quotes
}
}

Prog 3 Sum and Difference of Two Hardcoded Numbers

public class Program3 {


public static void main(String[] args) {
int a = 25, b = 15;
int sum = a + b;
int diff = a - b;
[Link]("Sum = " + sum);
[Link]("Difference = " + diff);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 1 of 22


Prog 4 Area and Perimeter of a Rectangle

public class Program4 {


public static void main(String[] args) {
double length = 12.5, breadth = 8.0;
double area = length * breadth;
double perimeter = 2 * (length + breadth);
[Link]("Area = " + area);
[Link]("Perimeter = " + perimeter);
}
}

Prog 5 Simple Interest Calculation

public class Program5 {


public static void main(String[] args) {
double p = 10000, r = 7.5;
int t = 3;
double si = (p * r * t) / 100.0;
double amount = p + si;
[Link]("Simple Interest = " + si);
[Link]("Total Amount = " + amount);
}
}

Prog 6 Convert Celsius to Fahrenheit

public class Program6 {


public static void main(String[] args) {
double celsius = 37.0;
double fahrenheit = (9.0 / 5.0) * celsius + 32;
[Link]("Temperature in Fahrenheit = " + fahrenheit);
}
}

Prog 7 Swap Two Numbers Using a Third Variable

public class Program7 {


public static void main(String[] args) {
int x = 10, y = 20;
[Link]("Before Swap: x = " + x + ", y = " + y);
int temp = x;
x = y;
y = temp;
[Link]("After Swap: x = " + x + ", y = " + y);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 2 of 22


Prog 8 Swap Two Numbers Without a Third Variable

public class Program8 {


public static void main(String[] args) {
int a = 10, b = 20;
a = a + b; // a = 30
b = a - b; // b = 10
a = a - b; // a = 20
[Link]("Swapped: a = " + a + ", b = " + b);
}
}

Prog 9 Calculate Compound Interest

public class Program9 {


public static void main(String[] args) {
double p = 5000, r = 10, t = 2;
double amount = p * [Link]((1 + r / 100), t);
double ci = amount - p;
[Link]("Compound Interest = " + ci);
}
}

Prog 10 Display ASCII Value of a Character

public class Program10 {


public static void main(String[] args) {
char ch = 'A';
int ascii = (int) ch;
[Link]("ASCII value of " + ch + " is " + ascii);
}
}

LEVEL 2: OPERATORS & USER INPUT VIA SCANNER (PROGRAMS 11 – 20)

Prog 11 Scanner Input for Student Marks and Average

import [Link];

public class Program11 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter marks in 3 subjects: ");
double m1 = [Link]();
double m2 = [Link]();
double m3 = [Link]();
double total = m1 + m2 + m3;
double avg = total / 3.0;
[Link]("Total Marks = " + total);
[Link]("Average Marks = " + avg);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 3 of 22


Prog 12 Arithmetic Operators Demonstration

import [Link];

public class Program12 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter two integers: ");
int num1 = [Link]();
int num2 = [Link]();
[Link]("Addition: " + (num1 + num2));
[Link]("Subtraction: " + (num1 - num2));
[Link]("Multiplication: " + (num1 * num2));
[Link]("Quotient: " + (num1 / num2));
[Link]("Remainder: " + (num1 % num2));
}
}

Prog 13 Convert Days into Years, Months, and Days

import [Link];

public class Program13 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter total days: ");
int totalDays = [Link]();
int years = totalDays / 365;
int remainingDays = totalDays % 365;
int months = remainingDays / 30;
int days = remainingDays % 30;
[Link](years + " Years, " + months + " Months, " + days + " Days");
}
}

Prog 14 Convert Total Seconds to Hours, Minutes, and Seconds

import [Link];

public class Program14 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter seconds: ");
int sec = [Link]();
int hrs = sec / 3600;
int mins = (sec % 3600) / 60;
int remSec = sec % 60;
[Link](hrs + " hrs " + mins + " mins " + remSec + " secs");
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 4 of 22


Prog 15 Prefix vs Postfix Operator Demonstration

public class Program15 {


public static void main(String[] args) {
int a = 5, b = 5;
[Link]("a++ evaluates to: " + (a++)); // 5
[Link]("Value of a after: " + a); // 6
[Link]("++b evaluates to: " + (++b)); // 6
}
}

Prog 16 Ternary Operator: Maximum of Two Numbers

import [Link];

public class Program16 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter two numbers: ");
int a = [Link]();
int b = [Link]();
int max = (a > b) ? a : b;
[Link]("Maximum number is: " + max);
}
}

Prog 17 Ternary Operator: Absolute Value

import [Link];

public class Program17 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int abs = (n < 0) ? -n : n;
[Link]("Absolute value is: " + abs);
}
}

Prog 18 Calculate Gross Salary with DA and HRA

import [Link];

public class Program18 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter basic salary: ");
double basic = [Link]();
double da = 0.40 * basic; // 40% DA
double hra = 0.20 * basic; // 20% HRA
double grossSalary = basic + da + hra;
[Link]("Gross Salary = Rs. " + grossSalary);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 5 of 22


Prog 19 Type Casting: Implicit vs Explicit

public class Program19 {


public static void main(String[] args) {
int i = 100;
double d = i; // Implicit casting

double x = 99.99;
int y = (int) x; // Explicit casting

[Link]("Implicit (int to double): " + d);


[Link]("Explicit (double to int): " + y);
}
}

Prog 20 Character Input using next().charAt(0)

import [Link];

public class Program20 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a character: ");
char ch = [Link]().charAt(0);
[Link]("You entered: " + ch);
}
}

LEVEL 3: MATH LIBRARY METHODS (PROGRAMS 21 – 25)

Prog 21 Hypotenuse of a Right-Angled Triangle

import [Link];

public class Program21 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter perpendicular and base: ");
double p = [Link]();
double b = [Link]();
double h = [Link]([Link](p, 2) + [Link](b, 2));
[Link]("Hypotenuse = " + h);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 6 of 22


Prog 22 Area of a Circle given Radius

import [Link];

public class Program22 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter radius: ");
double r = [Link]();
double area = [Link] * [Link](r, 2);
[Link]("Area of circle = " + area);
}
}

Prog 23 Rounding Methods (ceil, floor, round)

import [Link];

public class Program23 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a floating point number: ");
double num = [Link]();
[Link]("[Link](" + num + ") = " + [Link](num));
[Link]("[Link](" + num + ") = " + [Link](num));
[Link]("[Link](" + num + ") = " + [Link](num));
}
}

Prog 24 Absolute Value and Cube Root Functions

import [Link];

public class Program24 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a negative number and a double: ");
double a = [Link]();
double b = [Link]();
[Link]("Absolute value: " + [Link](a));
[Link]("Cube root: " + [Link](b));
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 7 of 22


Prog 25 Evaluate Algebraic Expression

import [Link];

public class Program25 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter values for a and b: ");
double a = [Link]();
double b = [Link]();
double result = [Link](([Link](a, 2) + [Link](b, 2)) / (2 * a * b));
[Link]("Result = " + result);
}
}

LEVEL 4: CONDITIONAL STATEMENTS (IF, IF-ELSE, SWITCH) (PROGRAMS


26 – 35)

Prog 26 Check Even or Odd Number

import [Link];

public class Program26 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
if (num % 2 == 0) {
[Link](num + " is Even");
} else {
[Link](num + " is Odd");
}
}
}

Prog 27 Check Voting Eligibility

import [Link];

public class Program27 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter age: ");
int age = [Link]();
if (age >= 18) {
[Link]("Eligible to vote.");
} else {
[Link]("Not eligible to vote. Wait " + (18 - age) + " more year(s).");
}
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 8 of 22


Prog 28 Find Largest of Three Numbers

import [Link];

public class Program28 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter three numbers: ");
int a = [Link](), b = [Link](), c = [Link]();
if (a >= b && a >= c) {
[Link](a + " is the largest.");
} else if (b >= a && b >= c) {
[Link](b + " is the largest.");
} else {
[Link](c + " is the largest.");
}
}
}

Prog 29 Check Leap Year

import [Link];

public class Program29 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter year: ");
int year = [Link]();
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
[Link](year + " is a Leap Year.");
} else {
[Link](year + " is NOT a Leap Year.");
}
}
}

Prog 30 Check Vowel or Consonant

import [Link];

public class Program30 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter an alphabet character: ");
char ch = [Link]().charAt(0);
ch = [Link](ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
[Link](ch + " is a Vowel.");
} else if ([Link](ch)) {
[Link](ch + " is a Consonant.");
} else {
[Link]("Not a valid alphabet letter.");
}
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 9 of 22


Prog 31 Grade Calculation using if-else-if

import [Link];

public class Program31 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter marks (0-100): ");
double marks = [Link]();
if (marks >= 90) [Link]("Grade: A");
else if (marks >= 75) [Link]("Grade: B");
else if (marks >= 60) [Link]("Grade: C");
else if (marks >= 40) [Link]("Grade: D");
else [Link]("Grade: F (Fail)");
}
}

Prog 32 Discount Slab System

import [Link];

public class Program32 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter shopping amount: ");
double amt = [Link]();
double discount = 0;

if (amt <= 2000) discount = 0;


else if (amt <= 5000) discount = amt * 0.05;
else if (amt <= 10000) discount = amt * 0.10;
else discount = amt * 0.15;

double netAmt = amt - discount;


[Link]("Discount = Rs. " + discount);
[Link]("Net Amount to Pay = Rs. " + netAmt);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 10 of 22


Prog 33 Electricity Bill Calculation (Slab Based)

import [Link];

public class Program33 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter units consumed: ");
int units = [Link]();
double bill = 0;

if (units <= 100) {


bill = units * 2.0;
} else if (units <= 300) {
bill = (100 * 2.0) + (units - 100) * 3.0;
} else {
bill = (100 * 2.0) + (200 * 3.0) + (units - 300) * 5.0;
}
[Link]("Total Electricity Bill = Rs. " + bill);
}
}

Prog 34 Menu-Driven Area Calculator using switch-case

import [Link];

public class Program34 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("--- MENU ---");
[Link]("1. Area of Circle");
[Link]("2. Area of Square");
[Link]("Enter choice (1-2): ");
int choice = [Link]();

switch (choice) {
case 1:
[Link]("Enter radius: ");
double r = [Link]();
[Link]("Area = " + ([Link] * r * r));
break;
case 2:
[Link]("Enter side length: ");
double s = [Link]();
[Link]("Area = " + (s * s));
break;
default:
[Link]("Invalid choice!");
}
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 11 of 22


Prog 35 Menu-Driven Temperature Converter

import [Link];

public class Program35 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius");
[Link]("Enter choice: ");
int ch = [Link]();

switch (ch) {
case 1:
[Link]("Enter Celsius: ");
double c = [Link]();
[Link]("Fahrenheit: " + ((9.0 / 5.0) * c + 32));
break;
case 2:
[Link]("Enter Fahrenheit: ");
double f = [Link]();
[Link]("Celsius: " + ((f - 32) * 5.0 / 9.0));
break;
default:
[Link]("Invalid Selection");
}
}
}

LEVEL 5: LOOPS (FOR, WHILE, DO-WHILE) (PROGRAMS 36 – 45)

Prog 36 Print First 10 Natural Numbers

public class Program36 {


public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
[Link](i + " ");
}
[Link]();
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 12 of 22


Prog 37 Sum of First N Natural Numbers

import [Link];

public class Program37 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter N: ");
int n = [Link]();
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += i;
}
[Link]("Sum of first " + n + " numbers = " + sum);
}
}

Prog 38 Factorial of a Number

import [Link];

public class Program38 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number: ");
int num = [Link]();
long fact = 1;
for (int i = 1; i <= num; i++) {
fact *= i;
}
[Link]("Factorial of " + num + " = " + fact);
}
}

Prog 39 Multiplication Table of a Number

import [Link];

public class Program39 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter table number: ");
int n = [Link]();
for (int i = 1; i <= 10; i++) {
[Link](n + " x " + i + " = " + (n * i));
}
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 13 of 22


Prog 40 Count Factors of a Number

import [Link];

public class Program40 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int count = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
count++;
}
}
[Link]("Total factors of " + num + " = " + count);
}
}

Prog 41 Check Prime Number

import [Link];

public class Program41 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int count = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0) count++;
}
if (count == 2) [Link](n + " is a Prime Number.");
else [Link](n + " is NOT a Prime Number.");
}
}

Prog 42 Print Fibonacci Series up to N Terms

import [Link];

public class Program42 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of terms: ");
int n = [Link]();
int a = 0, b = 1;
[Link]("Fibonacci Series: ");
for (int i = 1; i <= n; i++) {
[Link](a + " ");
int c = a + b;
a = b;
b = c;
}
[Link]();
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 14 of 22


Prog 43 Check Perfect Number

import [Link];

public class Program43 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int sum = 0;
for (int i = 1; i < num; i++) {
if (num % i == 0) sum += i;
}
if (sum == num) [Link](num + " is a Perfect Number.");
else [Link](num + " is NOT a Perfect Number.");
}
}

Prog 44 Find GCD / HCF of Two Numbers

import [Link];

public class Program44 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter two numbers: ");
int a = [Link]();
int b = [Link]();
int gcd = 1;
for (int i = 1; i <= a && i <= b; i++) {
if (a % i == 0 && b % i == 0) {
gcd = i;
}
}
[Link]("GCD/HCF = " + gcd);
}
}

Prog 45 Find LCM of Two Numbers

import [Link];

public class Program45 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter two numbers: ");
int a = [Link]();
int b = [Link]();
int max = (a > b) ? a : b;
while (true) {
if (max % a == 0 && max % b == 0) {
[Link]("LCM = " + max);
break;
}
max++;
}
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 15 of 22


LEVEL 6: NUMBER MANIPULATION PROBLEMS (PROGRAMS 46 – 52)

Prog 46 Extract and Display Digits of a Number

import [Link];

public class Program46 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
[Link]("Digits from right to left: ");
while (n > 0) {
int digit = n % 10;
[Link](digit + " ");
n /= 10;
}
[Link]();
}
}

Prog 47 Sum of Digits of a Number

import [Link];

public class Program47 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int sum = 0;
while (n > 0) {
sum += (n % 10);
n /= 10;
}
[Link]("Sum of digits = " + sum);
}
}

Prog 48 Reverse a Number

import [Link];

public class Program48 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int rev = 0;
while (n > 0) {
int d = n % 10;
rev = rev * 10 + d;
n /= 10;
}
[Link]("Reversed Number = " + rev);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 16 of 22


Prog 49 Check Palindrome Number

import [Link];

public class Program49 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int temp = n, rev = 0;
while (temp > 0) {
rev = rev * 10 + (temp % 10);
temp /= 10;
}
if (rev == n) [Link](n + " is a Palindrome Number.");
else [Link](n + " is NOT a Palindrome Number.");
}
}

Prog 50 Check Armstrong Number (for 3-digit numbers)

import [Link];

public class Program50 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a 3-digit number: ");
int n = [Link]();
int temp = n, sum = 0;
while (temp > 0) {
int d = temp % 10;
sum += (d * d * d);
temp /= 10;
}
if (sum == n) [Link](n + " is an Armstrong Number.");
else [Link](n + " is NOT an Armstrong Number.");
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 17 of 22


Prog 51 Check Special / Krishnamurthy Number

import [Link];

public class Program51 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int temp = n, sum = 0;
while (temp > 0) {
int d = temp % 10;
int fact = 1;
for (int i = 1; i <= d; i++) fact *= i;
sum += fact;
temp /= 10;
}
if (sum == n) [Link](n + " is a Special/Krishnamurthy Number.");
else [Link](n + " is NOT a Special Number.");
}
}

Prog 52 Check Niven / Harshad Number

import [Link];

public class Program52 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
int temp = n, sum = 0;
while (temp > 0) {
sum += (temp % 10);
temp /= 10;
}
if (n % sum == 0) [Link](n + " is a Niven / Harshad Number.");
else [Link](n + " is NOT a Niven Number.");
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 18 of 22


LEVEL 7: SERIES & NESTED LOOP PATTERNS (PROGRAMS 53 – 60)

Prog 53 Sum of Series: S = 1 + 2 + 3 + ... + n

import [Link];

public class Program53 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter n: ");
int n = [Link]();
int sum = 0;
for (int i = 1; i <= n; i++) sum += i;
[Link]("Sum = " + sum);
}
}

Prog 54 Sum of Series: S = 1 + 1/2 + 1/3 + ... + 1/n

import [Link];

public class Program54 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter n: ");
int n = [Link]();
double sum = 0.0;
for (int i = 1; i <= n; i++) {
sum += 1.0 / i;
}
[Link]("Sum of series = " + sum);
}
}

Prog 55 Sum of Series: S = x^1 + x^2 + x^3 + ... + x^n

import [Link];

public class Program55 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter x and n: ");
double x = [Link]();
int n = [Link]();
double sum = 0;
for (int i = 1; i <= n; i++) {
sum += [Link](x, i);
}
[Link]("Sum = " + sum);
}
}

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 19 of 22


Prog 56 Right-Angled Star Triangle Pattern

public class Program56 {


public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}
}
}

EXPECTED PATTERN OUTPUT:


*
* *
* * *
* * * *
* * * * *

Prog 57 Right-Angled Number Triangle Pattern

public class Program57 {


public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
[Link]();
}
}
}

EXPECTED PATTERN OUTPUT:


1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 20 of 22


Prog 58 Repeating Row-Number Triangle Pattern

public class Program58 {


public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link](i + " ");
}
[Link]();
}
}
}

EXPECTED PATTERN OUTPUT:


1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Prog 59 Inverted Star Triangle Pattern

public class Program59 {


public static void main(String[] args) {
for (int i = 5; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link]("* ");
}
[Link]();
}
}
}

EXPECTED PATTERN OUTPUT:


* * * * *
* * * *
* * *
* *
*

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 21 of 22


Prog 60 Floyd's Triangle Pattern

public class Program60 {


public static void main(String[] args) {
int k = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
[Link]((k++) + " ");
}
[Link]();
}
}
}

EXPECTED PATTERN OUTPUT:


1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Prepared by: Rahul Kumar Lal | ICSE Class 9 Java Page 22 of 22

You might also like