Coming soon - Get a detailed view of why an account is flagged as spam!
view details
3
[Java] Why won't my for loop run?
Author Summary
pds12345 is in Java
Post Body

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.

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,878
Link Karma
399
Comment Karma
8,080
Profile updated: 1 month ago
Posts updated: 11 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
11 years ago