Write a program using do loop to exit only when zero is entered.
import java.io.*;
class do_loop
{
public static void main(String [] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a;
do
{
System.out.println("Press 0 to exit");
a=Integer.parseInt(br.readLine());
}
while (a!=0);
}
}
This program can be used in :-
1. Menu driven program( if the user entered a wrong choice he will be prompted to enter the correct choice it will continue until the choice is correct).
2.In projects to increase number of lines. :-)
MORE PROGRAMS
class do_loop
{
public static void main(String [] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a;
do
{
System.out.println("Press 0 to exit");
a=Integer.parseInt(br.readLine());
}
while (a!=0);
}
}
This program can be used in :-
1. Menu driven program( if the user entered a wrong choice he will be prompted to enter the correct choice it will continue until the choice is correct).
2.In projects to increase number of lines. :-)
MORE PROGRAMS
Post a Comment