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
Saturday, July 10, 2010
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
IF ELSE sample program
This program will determine the age of person if 18 above or 18 below. the program will show message " Your qualified to vote" if the age of person is 18 above, else the program will show message " Your not qualified to vote" if the age of person is 18 below.
here is the sample program.
import java.io.*;
public class SampleIf
{
public static void main(String args[])
{
//declaration
int age=18;
if(age>=18)
{
System.out.println("Your Qualified to Vote");
}
else
{
System.out.print("Your not Qualified to vote");
}
}
}
here is the sample program.
import java.io.*;
public class SampleIf
{
public static void main(String args[])
{
//declaration
int age=18;
if(age>=18)
{
System.out.println("Your Qualified to Vote");
}
else
{
System.out.print("Your not Qualified to vote");
}
}
}
Wednesday, July 7, 2010
If Statement
IF statement - is a conditional statement.
syntax:
if(conndition)
{
statement 1;
}
IF ELSE - also conditional statement that the program will choose the true statement or false statement depending on thier condition.
syntax:
if(condition)
{
statement 1;
stmt 2;
}
else
{
statement 1;
stmt 2;
}
syntax:
if(conndition)
{
statement 1;
}
IF ELSE - also conditional statement that the program will choose the true statement or false statement depending on thier condition.
syntax:
if(condition)
{
statement 1;
stmt 2;
}
else
{
statement 1;
stmt 2;
}
Labels:
if,
if else,
if else in java,
if statement,
java if
Thursday, July 1, 2010
Sample Program Using Class and Objects
I will create a program using classes and objects. I Used two class name which are MainProgram and Message.
In class name MainProgram, the user will input thier name, and this input data will pass to class Message to print.
Program Code:
import java.io.*;
import java.util.Scanner;
public class MainProgram
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
String name="";
System.out.print("Enter your name:");
input=name.nextLine();
//calling the class
//create an object to call the method in class Message
Message x = new Message();
x.printing(name);
}
}
Class Program:
class Message
{
public void printing(String nm)
{
System.out.print("Your name is:" + nm);
}
}
If you run this program you go to the MainProgram . The mainProgram will process all class program.
Output:
Your name is: Jaypee
In class name MainProgram, the user will input thier name, and this input data will pass to class Message to print.
Program Code:
import java.io.*;
import java.util.Scanner;
public class MainProgram
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
String name="";
System.out.print("Enter your name:");
input=name.nextLine();
//calling the class
//create an object to call the method in class Message
Message x = new Message();
x.printing(name);
}
}
Class Program:
class Message
{
public void printing(String nm)
{
System.out.print("Your name is:" + nm);
}
}
If you run this program you go to the MainProgram . The mainProgram will process all class program.
Output:
Your name is: Jaypee
Compute two numbers using java
this program will compute two numbers and get the sum, difference, product and quotient. x=5, y=6.
program code:
import java.io.*;
public class Computation
{
public static void main(String args[])
{
//Declaration
int x=5;
int y=6;
int sum=0;
int diff=0;
int prod=0;
int quo=0;
//computation
sum= x + y;
diff= x - y;
prod= x * y;
quo = x / y;
//Display result
System.out.println("The sum is:" + sum);
System.out.println("The diff is: + diff);
System.out.println("The prod is: + prod);
System.out.print("The Quo is: + quo);
}
}
program code:
import java.io.*;
public class Computation
{
public static void main(String args[])
{
//Declaration
int x=5;
int y=6;
int sum=0;
int diff=0;
int prod=0;
int quo=0;
//computation
sum= x + y;
diff= x - y;
prod= x * y;
quo = x / y;
//Display result
System.out.println("The sum is:" + sum);
System.out.println("The diff is: + diff);
System.out.println("The prod is: + prod);
System.out.print("The Quo is: + quo);
}
}
Subscribe to:
Posts (Atom)