There is not much difference between for loop and while loop. The main difference is that the for loop contain its all condition and statement within the loop and on the other hand in while loop the condition is outside of the loop.
Source Code
package com.ancodingpoint.www; import java.util.Scanner; public class While_Loop{ public static void main(String[] args) { Scanner input = new Scanner (System.in); int num [] = new int [5]; int a =0; int b =0; while (a<5) { System.out.println(" Enter Your Number Here ...... !"); num[a] = input.nextInt(); a++; } System.out.println(" Now Again printing these Number with using While Loop "); while (b<5) { System.out.println(num[b]); b++; } } }
0 comments:
Post a Comment