you are given with a string
find the total number present in it
Eg: if the string is *asvebs45ags2vxhs6ba100ndg*.
then your output should be 4
in c program
Answers
You just need to figure out the set of loops and you must check the two figures of the Java programming. Here you can find one row which is increasing and another one is decreasing.
mport java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value for n: ");
int n=sc.nextInt(); //Taking User Input for n
for(int i=0;i<n;i++) //First Loop runs for increasing length of rows
{
for(int j=0;j<=i;j++) //Loop for printing the increasing numbers on each row
{
System.out.print(j+1);
}
for(int j=i;j>0;j--) //Loop for printing the decreasing numbers on each row
{
System.out.print(j);
}
System.out.println(); //Printing a blank line after a row is completed
}
//The same above loop of i is repeated with a different range for decreasing length of rows
//All inner contents are the same
for(int i=n-2;i>=0;i--)
{
for(int j=0;j<=i;j++)
{
System.out.print(j+1);
}
for(int j=i;j>0;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}