There are four types of streams: InputStream, OutputStream, Reader, and Writer. | |||||||||||||||||
1. Reader. A stream to read characters. 2. Writer. A stream to write characters. 3. InputStream. A stream to read binary data. 4. OutputStream. A stream to write binary data.
|
Tuesday, August 3, 2010
File Streams
Labels:
File and Streams,
File Stream,
inputStream,
OutputStream,
printwiter,
Stream
while statement program
Problem: Create program that ask the user to input "How many hello world you want to print" and the output show number and hello world.
import java.util.Scanner;
public class helloworld
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
int start=1;
System.out.print("How hello world you want to display");
num=input.nextInt();
while(start<= num)
{
System.out.println(start + ".Hello");
start++;
}
}
}
import java.util.Scanner;
public class helloworld
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
int start=1;
System.out.print("How hello world you want to display");
num=input.nextInt();
while(start<= num)
{
System.out.println(start + ".Hello");
start++;
}
}
}
Monday, August 2, 2010
Sample Program of while Loop
this program is using while statement to print 5 hello world in your screen .
here is a sample program;
import java.io.*;
public class samplewhile
{
public static void main(String args[])
{
//declaration
int start=1;
while(start<=5)
{
System.out.print("Hello World");
start++;
}
}
}
here is a sample program;
import java.io.*;
public class samplewhile
{
public static void main(String args[])
{
//declaration
int start=1;
while(start<=5)
{
System.out.print("Hello World");
start++;
}
}
}
While Loop
While Loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.
The while construct consists of a block of code and a condition. The condition is evaluated, and if the condition is true, the code within the block is executed. This repeats until the condition becomes false. Because while loops check the condition before the block is executed, the control structure is often also known as a pre-test loop. Compare with the do while loop, which tests the condition after the loop has executed.
syntax of while loop
initialization;
while(condition)
{
Statements..
inc/dec;
}
The while construct consists of a block of code and a condition. The condition is evaluated, and if the condition is true, the code within the block is executed. This repeats until the condition becomes false. Because while loops check the condition before the block is executed, the control structure is often also known as a pre-test loop. Compare with the do while loop, which tests the condition after the loop has executed.
syntax of while loop
initialization;
while(condition)
{
Statements..
inc/dec;
}
Labels:
di while loop,
syntax of while loop
Looping
Looping is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement. Unlike many other kinds of loops, such as the while loop, the for loop is often distinguished by an explicit loop counter or loop variable.
there are three different type of looping, used in programming.
1. while Loop
2. do while Loop
3. for Loop
there are three different type of looping, used in programming.
1. while Loop
2. do while Loop
3. for Loop
Labels:
di while loop,
Do while Loop,
for loop,
looping
sample program of switch statement
This program will show to you how switch statement execute by the java compiler.
import java.util.Scanner;
public class SampleSwitch
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
//declaration
int num;
System.out.print("Enter a number:");
num=input.nextInt();
Switch(num)
{
case 1:
case 3:
case 5:
case 7:
case 9:
System.out.print("You enter odd number:");
break;
case 2:
case 4:
case 6:
case 8:
case 10:
System.out.print("You enter even number:");
break;
default:
System.out.print("Your number you enter is not found in the case");
}
}
}
understand this program and practice to create your own program using switch statement,,
import java.util.Scanner;
public class SampleSwitch
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
//declaration
int num;
System.out.print("Enter a number:");
num=input.nextInt();
Switch(num)
{
case 1:
case 3:
case 5:
case 7:
case 9:
System.out.print("You enter odd number:");
break;
case 2:
case 4:
case 6:
case 8:
case 10:
System.out.print("You enter even number:");
break;
default:
System.out.print("Your number you enter is not found in the case");
}
}
}
understand this program and practice to create your own program using switch statement,,
Switch Statement syntax
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.
}
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.
}
Subscribe to:
Posts (Atom)