Sunday, April 18, 2010

user input in java

The program will ask the user to input name, address and the program will show what they input.
we use here the namespace which is the util.scanner.

User input in java using string;

name of java file: javainput

Sample program:

import java.util.scanner;
public class javainput
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);

//declaration
String name,address;
System.out.println("Enter your name:");
name=input.next();

System.out.println("Enter your name:");
address=input.next();

//displaying the result
System.out.print("Your Name:" + name);
System.out.print("Your Name:" + add);
}
}

String in Java

he String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class.

Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:

     String str = "abc";  
sample program.

import java.io.*;

public class stringsample
{
public static void main(String args[])
{
System.out.print("Hello World");
System.out.print("Welcome to my String Java program");

}
}

Tuesday, April 13, 2010

while loop sample program

import java.io*;

public class loopwhile
{
public static void main(String args[])
{
int x=1;
while(x<=10)
{
System.out.print(x);
x++;
}
}
}

Monday, April 12, 2010

while Loop

Looping is a part of programming which is the program executed continously until it reaches the

Sunday, April 4, 2010

If Statement

if statement is a conditional statement in programming. In this statement we are using the conditonal operators. this is true or false only. if the conditional statement is true the program execute the true statements, if the conditional statement is false the program execute the false statements.

sample program:

this program will show to you if the grade of students is greater than 75 the program will show message "Your passed" else "Sorry your Failed".

import java.io.*;

public class sample
{
public static void main(String args[])
{
int average=75;

if(average>=75)
{
System.out.print("Your Passed");
}
else
{
System.out.print("Your Failed");
}

}

}

Conditional Operators

Conditional operators are used in programming to perform condition in a program to execute statement.


1. (>) greater than
2. (<) Less than
3. (>=) Greater than equal
4. (<=) Less that equal
5. (==) Equal
6. (!=) not equal

next lesson is if statement.

Keywords in Java programming

The following keywords in java programming are:

abstract assert boolean break byte case catch char class

const continue default do double else enum extends final

finally float for goto if implements import instanceof

int interface long native new package private protected public

return short static strictfp super switch synchronized this throw

throws transient try void volatile while

it is used in java programming to implement a code and generate a function to have a correct statement.