473,507 Members | 4,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find a 'carriage return' and loop back to main until user enters a string

1 New Member
excuse me, simple question
I want a user to enter a string so that I may recursively call it to reverse it.
Just one thing, i wanna make sure the user did not enter a carriage return, if he/she did, it will loop and ask them to enter a string again. Basically error prevention. So I tried a while (x=="\n") or "" or "\r" where x is my string..it did not do anything. BTW i am using Eclipse.
So basically how can i do a loop in main that will keep asking user for a string and checking whether or not he enterd a "Enter"
Thanks ahead of time.

The prog:
**********************************

import java.io.*;
import java.util.Scanner;
public class stringreverse
{

public static void stringreversed(String s, int n)
{
if (n==0){
System.out.print("you entered nada");
return;}
else{

System.out.print(s.charAt(n-1));
stringreversed(s,n-1);
}
}

public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("What do you want to reverse? ");
int t;
String x = scan.next();
while (x !="")
{
t = x.length();

stringreversed(x,t);
}

else
System.out.print("You entered an empty string,try again");
//want it to loop back to main here until a string is entered









}
}
Mar 29 '10 #1
1 3071
jkmyoung
2,057 Recognized Expert Top Contributor
use the nextLine() function if you're looking for line by line input as opposed to word by word input.

scan.next(); will never return "" unless you have changed the input delimiters.
Mar 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1806
by: Madestro | last post by:
Hi guys, I am making a small program to retrieve e-mails from POP accounts. I got all the e-mail parsing stuff figured out, but I cannot seem to come up with a way to find out which e-mails are...
5
2167
by: Ferdi | last post by:
I have a WebForm with one control: A HTML INPUT control with the property "runat=server" set. If this page is running and I set the cursor in this control and enter "Carriage return", the page...
1
2204
by: Steve | last post by:
I have a simple form with a textbox and a command button, both web form controls (not raw HTML controls). I notice that when the user enters text in the textbox and hits carriage return, the form...
2
2320
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
27
4583
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
1
1224
by: Arpan | last post by:
A class file named "Users.vb" has the following code: Namespace Users Public Class UserDetails Public FirstName As String Public LastName As String Public UserName As String Public Password...
8
10146
by: mharry | last post by:
Hi guys! I have a VB6 program that uses FileSystemObject to read a csv file,Basically I want to add commas into a specified locations of the csv. The program works fine on a generic csv file...
4
2762
by: saytri | last post by:
I have a problem with do while loop. I am displaying a dialogue box where a person should enter the type of quiz he had performed. The problem is that the user should enter only the following 3...
11
12556
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message...
1
4569
by: robotlizz | last post by:
Hello - I am a brand new at Java and I am having a hard time with a program I have to turn in tomorrow. I can not get the 'Q' option to work and the loop goes on forever. I've tried to go over the...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.