the syntax of Switch Statement:
switch(value)
{
case value1:
statement 1;
break;
case value 2:
statement 2;
break;
case value n:
statement ...
break;
default:
statement;
}
i hope you understand this syntax in switch statement to create running program.
}
Monday, August 2, 2010
Switch Case Statement
Switch Case Statement is a type of selection control statement that exists in most modern imperative programming languages (e.g., Pascal, C, C++, C#, and Java). Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multiway branch (or "goto", one of several labels). The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics permit), offering the potential of faster execution through compiler optimization. In some programming languages, a statement that is syntactically different but conceptually the same as the switch statement is known as a case statement, select statement or inspect instruction.
Saturday, July 10, 2010
Using syst.out.print sample program
This program will show how to used system.out.print to show a message or output of the program.
this is used to show ther output in screen.
here is a sample program.
import java.io.*;
public class sampleprogram
{
public static void main(String args[])
{
System.out.println("Hello World");
System.out.println("I am Jaypee Cezar");
System.out.println("I am a programmer");
System.out.print("I hope you learn in my blog");
}
}
here is the output :
Hello World
I am Jaypee Cezar
I am a programmer
I hope you learn in blog
this is used to show ther output in screen.
here is a sample program.
import java.io.*;
public class sampleprogram
{
public static void main(String args[])
{
System.out.println("Hello World");
System.out.println("I am Jaypee Cezar");
System.out.println("I am a programmer");
System.out.print("I hope you learn in my blog");
}
}
here is the output :
Hello World
I am Jaypee Cezar
I am a programmer
I hope you learn in blog
Labels:
display hello world,
jaypee cezar,
my blog,
programmer
Thursday, July 8, 2010
Relational Operators in programming
This operator used in programming to make a decision making. this operator is answer by true or false or yes or no only. the program execute depending on the result of operations.
These are the Relational Operators
> greater than
>= greater than or equal
< less than
<= less than or equal
== equal
!= not equal
These are the Relational Operators
> greater than
>= greater than or equal
< less than
<= less than or equal
== equal
!= not equal
Java Operators
Programming Operators are use in computing the numbers using programming.
here are the the operators used in programming.
name Symbols
1. Addition +
2. Subtraction -
3. Multiplication *
4. Division /
5. Modulo % - this operator used to get the remainder
here are the the operators used in programming.
name Symbols
1. Addition +
2. Subtraction -
3. Multiplication *
4. Division /
5. Modulo % - this operator used to get the remainder
Labels:
operators,
Operators in java,
programming operators
Escape sequence in programming
This are the common escape sequences in programming.
\n - newline.
\t - Horizontal Tab
\r - Carriage return
\\ - Backslash
\" - Double Quote
\n - newline.
\t - Horizontal Tab
\r - Carriage return
\\ - Backslash
\" - Double Quote
IF ELSE statement sample program
This program will compute the 3 grades and get the average. the program will show a message "Your Passed" if the average is 75 above. else the program will show a message " Your Failed" if the average is Below 75.
here is the program.
import java.io.*;
public class ComputeAverage
{
public static void main(String args[])
{
//declaration of variables
int math=90;
int PE=90;
int prog=95;
int ave=0;
//Compute the average
ave=(math + PE + prog)/3;
//display the average
System.out.print("Your average is:" + ave);
//checking the average if it is 75 above or below 75 using if statement
if(ave>=75)
{
System.out.print("Your Passed");
}
else
{
System.out.print("Your Failed");
}
}
}
here is the program.
import java.io.*;
public class ComputeAverage
{
public static void main(String args[])
{
//declaration of variables
int math=90;
int PE=90;
int prog=95;
int ave=0;
//Compute the average
ave=(math + PE + prog)/3;
//display the average
System.out.print("Your average is:" + ave);
//checking the average if it is 75 above or below 75 using if statement
if(ave>=75)
{
System.out.print("Your Passed");
}
else
{
System.out.print("Your Failed");
}
}
}
Labels:
Average,
get the average,
if else in java,
if else statement
Subscribe to:
Posts (Atom)