The Artima Developer Community
Sponsored Link

Java Answers Forum
How To Write A Code "Press Any Key to continue"

1 reply on 1 page. Most recent reply: Feb 20, 2004 1:48 AM by Viswanatha Basavalingappa

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
leonglkw

Posts: 43
Nickname: leonglkw
Registered: Feb, 2004

How To Write A Code "Press Any Key to continue" Posted: Feb 20, 2004 12:19 AM
Reply to this message Reply
Advertisement
Can you guys advise how to write a code "Press Any Key to continue" so that once the user press Any Key, the program continue with the rest of the functions?

Thanks a million.


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: How To Write A Code "Press Any Key to continue" Posted: Feb 20, 2004 1:48 AM
Reply to this message Reply
Yes, you can do here is the algorithm to do...

function doSmoething()
{
doX();
doY();
System.out.println("Press Any Key to display next..!");
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
int ch = stdin.read();
if(ch !=-1)
doZ();
else
break;
}


--------------------------

Example code for the same.....

import java.io.*;
class PressAnyKey
{
public static void main(String[] args)
{
try
{
System.out.println("Hello PressAnyKey Example!");
for(int i = 1;i<= 10 ;i++)
{
System.out.println("--------------------------------------");
for(int j =1 ;j<=10;j++)
{
System.out.println( i + " x "+ j + "= " + i*j);
}
if(i>=5)
{
System.out.println("Press Any Key to display next..!");
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
int ch = stdin.read();
if(ch !=-1)
continue;
else
break;

}
System.out.println("--------------------------------------");
}
}catch(IOException io)
{
System.out.println("ERROR" + io);
}
}
}

---------------------

Thanks
Viswa
--------

Flat View: This topic has 1 reply on 1 page
Topic: can  cmp entity bean use microsoft access as a database? Previous Topic   Next Topic Topic: Linear Searches

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use