Showing posts with label for loop code. Show all posts
Showing posts with label for loop code. Show all posts

Tuesday, November 25, 2014

For loop example in java

In example, Test class has a main method and local variable with a for loop inside it and printing the looped value on console.
 public class Test   
 {  
      public static void main(String args [])  
      {  
           int total=0;  
           int a=0;  
           int num=4321;  
           for(int x=0;x<4;x++)  
           {  
                a=num/10;  
                num=num/10;  
                System.out.println(a);  
                total +=a;  
           }  
                System.out.println(total);  
      }  
 }