Presentation is loading. Please wait.

Presentation is loading. Please wait.

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.

Similar presentations


Presentation on theme: "Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate."— Presentation transcript:

1 Continuation of chapter 6…

2 Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate pattern by using while loop. public class Pattern 1 { 1 2 public static void main(String args[]) 1 2 3 { 1 2 3 4 int a = 1; 1 2 3 4 5 while (a<=5) { int b = 1; while(b<=a) { System.out.print(b); b++; } System.out.println(); }

3 Nested for loop When we apply a for loop within another for loop, the structure is termed as nested for loop. Q. A program to display the given pattern. public class pattern 1 { 1 2 Public static void main(String args[]) 1 2 3 { 1 2 3 4 int a, b; 1 2 3 4 5 for(a=1; a<=5; a++) { for(b=1; b<=a;b++) System.out.print(b); System.out.println(); }

4 Q. Write a program in JAVA to display the given pattern 1 2 3 4 5 6 7 1 2 3 4 5 1 2 3 1

5 Q. Write a program in JAVA to display the given pattern 1 2 3 4 5 6 7 1 2 3 4 5 1 2 3 1 public class Pattern { Public static void main(String args[]) { int i, j ; for(i=7 ; i>=1 ; i=1-2) { for(j=1 ; j<=i ; j++) System.out.print(j+ ); System.out.println(); }

6 Q. Write a program to find the sum of series, taking the value of a and n from the user. S = a/2 + a/3 + a/4 + …………………………………………………+ a/n import java.io.*; pubic class series { public static void main (String args[]) throws IOException { int a,i,n; double s=0; InputStreamReader read = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println(Enter the value of a and n); a= Integer.parseInt(in.readLine()); n=Integer.parseInt(in.readLine()); for(i=1; i<=n; i++) s= s+a / (i+1); System.out.println(Sum of the series = +s); }

7 Q. Write a program to find the sum of series, taking the value of a and n from the user. s=a+1/2 + a+3/4 + a+5/6 …………………………………………+ to n import java.io.*; pubic class series { public static void main (String args[]) throws IOException { int a,i,n; double s=0; InputStreamReader read = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println(Enter the value of a and n); a= Integer.parseInt(in.readLine()); n=Integer.parseInt(in.readLine()); for(i=1; i<=n; i=i+2) S=S+(a+i) / (i+1); System.out.println(Sum of the series = +s) }


Download ppt "Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate."

Similar presentations


Ads by Google