I just posted on here last night while I was going over a lesson and now I have to do a quick mini-project and have fun into some trouble!
I need to write a program that will allow a user to input his/her name. Than, using a for-loop and the String meathod, substring() produce a printout of the reversal of the name.
import java.io.*;
import java.util.*;
public class nameReversed {
public static void main(String[] args) {
//Allows the input of the user's name
Scanner kbReader = new Scanner(System.in);
System.out.print("Enter Your name, please... ");
String fullName = kbReader.nextLine();
int y = fullName.length();
int p = y;
for (int x = 1; x == p; x ) {
System.out.print(fullName.substring(y));
y--;
}
}
}
This is what I have and after I input my name, I just get a blank line back and the code is done, with no errors.
It seems to me my for-loop is not running... but I am unsure as to why. Any help would be appreciated!
I have also tried making a second string with the value of "" and tried appending each substring to the new variable and printing the entire variable outside the for-loop but I had the same results, which is another reason I am led to believe that my for-loop simply is not running.
Edit: Thank you all! Was a simple mistake... but those always seem to be the ones everyone misses.
Subreddit
Post Details
- Posted
- 11 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...