next


Java Online Compiler

Unconditional Statements In java

Unconditional Statements:

Unconditional Statements are classified into following types.
  1. continue
  2. break
  • continue:
  • 'continue' statement is used to continue the loop( It skip the one iteration if the condition is true).
    syntax:
            if(condion)
            {
            continue;
            }
        
  • break:
  • 'break' statement is used to break the loop.
    syntax:
            if(condion)
            {
            break;
            }
        
Continue Statement
UnConditional


class ContinueStatement
{
public static void main(String args[])
{

int i;
for(i=0;i<=10;i++)
{
if(i==5)continue;
System.out.println(i);
}
}
}
}

Break Statement
                                

class BreakStatement
{
public static void main(String args[])
{

int i;
for(i=0;i<=10;i++)
{
if(i==5)break;
System.out.println(i);
}
}
}

Write A Simple Program Without Using Main Method

class WithoutMain
{
 static
 {
  int x=10,y=20;
  System.out.println("Addition values is "+(x+y));
  System.exit(0); 
 }
}

Print ASCII Values.

import java.util.*;
class Ascii
{
public static void main(String args[])
{
char ch,i;
Scanner s=new Scanner(System.in);
System.out.println("enter small or capital alphabet");
ch=s.next().charAt(0);
if(ch>='a' && ch<='z')
{
for(i='a';i<='z';i++)
{
System.out.println(i+"="+(int)i);
}
}
else
{
for(i='A';i<='Z';i++)
{
System.out.println(i+"="+(int)i);
}
}
}
}