0% found this document useful (0 votes)
7 views2 pages

Floyds Traingle Program

The document contains a Java program that implements two functionalities based on user input: calculating a series sum or generating Floyd's Triangle. The program uses a scanner to capture user choices and employs loops to compute and display results. Key variables are defined to manage user input, calculations, and output formatting.

Uploaded by

98hwkb4rzt
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)
7 views2 pages

Floyds Traingle Program

The document contains a Java program that implements two functionalities based on user input: calculating a series sum or generating Floyd's Triangle. The program uses a scanner to capture user choices and employs loops to compute and display results. Key variables are defined to manage user input, calculations, and output formatting.

Uploaded by

98hwkb4rzt
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
You are on page 1/ 2

Floyds Traingle Program

// Importing Packages

import java.util.*;

import java.io.*;

import java.lang.*;

public class Floyds_Traingle // declaring class

{ // opening braces of class

public static void main(String []args) // declaring main method

{ // openiong braces of main method

Scanner pa = new Scanner(System.in); // declaring scanner class

System.out.println("Enter 1 for series and 2 for floyds traingle");

int c = pa.nextInt(); // storing user's choice

switch(c) // decalring switch case

{ // opening braces of switch statement

case 1: // Series

double x=-10,y=5.5,z=0;

while(x!=10)

z= x*x*x + 0.5*x/y;

x+=2;

System.out.println("Sum of series is "+z); // Printing series

break;

case 2: // Floyds Traingle

System.out.println("Enter number of rows");

int n = pa.nextInt();

int k=1;

for(int i =1;i<=n;i++)

for(int j=1;j<=i;j++)

{
System.out.print(k+" ");

k++;

System.out.println();

} // closing braces of switch statement

} // closing barces of main method

} // closing braces of class

VARIABLE DATA TYPE FUNCTION


c Integer To store the user's choice
x Double To increase to 10
y Double To store constant value of 5.5
z Double To store the sum of the series
i Integer To create rows
j Integer To create column
k Integer To print the traingle
n Integer To store the numbers of rows

You might also like