1.

06 Using the switch statement: write a menu driven program for the followingi. to print Floyd triangle12 34 5 67 8 9 1011 12 13 14 15ii. to print the pattern5 5 45 4 35 4 3 2 5 4 3 2 1​

Answer»

program will prompt user for number of rows and based on the input, it WOULD PRINT the Floyd’s TRIANGLE having the same number of rows./* Program: It Prints Floyd's triangle based on user inputs * Written by: Chaitanya from beginnersbook.com * Input: Number of rows * output: floyd's triangle*/import java.util.Scanner;class FloydTriangleExample{ public static void main(String args[]) { int rows, number = 1, counter, j; //To get the user's input Scanner input = new Scanner(System.in); System.out.println("Enter the number of rows for floyd's triangle:"); //Copying user input into an integer variable named rows rows = input.nextInt(); System.out.println("Floyd's triangle"); System.out.println("****************"); for ( counter = 1 ; counter <= rows ; counter++ ) { for ( j = 1 ; j <= counter ; j++ ) { System.out.print(number+" "); //Incrementing the number value number++; } //For new line System.out.println(); } }}Output:Enter the number of rows for floyd's triangle:6Floyd's triangle****************1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21Enjoyed this post? Try these related postsJava program to DISPLAY prime numbers from 1 to 100 and 1 to nHow to convert a char array to a string in Java?Java Program to find ASCII value of a CharacterJava Program to find duplicate Characters in a StringJava Program to check Even or Odd numberJava Program to check Vowel or Consonant using Switch Case



Discussion

No Comment Found