Feb 12, 2012

[Java] continue, break

// Java
// continue, break


import java.util.*;

class continue_break
{
 public static void main(String[] args)
 {
 
        System.out.println("Input number between 1 and 5");
        Scanner scan = new Scanner (System.in);
        int input;
        
        while(!scan.hasNextInt())
        {
            scan.next();   // if input is not integer value, ignore it.
            System.err.println("Input should be integer value");
        }
        
        input=scan.nextInt();  
        
        
        while(input<5)
        {
            System.out.println(input + " + 1 = " + (input+1));
            input=input+1;
            
            if(input<=3)
            {
                System.out.println("value is not yet greater than 3");
                continue;
            } else 
                {
                    System.out.println("current value = " +input + " >3");
                    break;
                }
        }
                

        for(int num=0; num<1000; num++)
        {
            if(num%12==0 && num%18==0)
            {
                System.out.print(num + "  ");
                continue;
            } 
        }
 }
}

No comments:

Post a Comment