---
title: "Java program looping help! I need to restart the program via a y/n input"  
description: "Java program looping help! I need to restart the program via a y/n input"  
author: "marcel ethan"  
published: 2014-12-30  
updated: 2014-12-30  
canonical: https://www.mindstick.com/forum/12830/java-program-looping-help-i-need-to-restart-the-program-via-a-y-n-input  
category: "java"  
tags: ["java", "loop"]  
reading_time: 1 minute  

---

# Java program looping help! I need to restart the program via a y/n input

Okay so I made a [program to check](https://www.mindstick.com/forum/157542/write-a-java-program-to-check-if-a-list-of-integers-contains-only-odd-numbers) for palindromes but I need to be able to restart the program by asking if the [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) wants to try again y/n? But I can't seem to loop it correctly. Help me! P.S [sorry](https://yourviews.mindstick.com/view/81321/ekta-kapoor-s-sorry-is-not-acceptable) for formatting.\

```
import java.util.*;import java.util.Scanner;class PalidromeTester{public static void main(String args[]){boolean play = true; while(play == true){String inputString;Scanner in = new Scanner(System.in);System.out.println("Please enter a potential palindrome:");inputString = in.nextLine();int length  = inputString.length();int i, begin, end, middle;begin  = 0;end    = length - 1;middle = (begin + end)/2;for (i = begin; i <= middle; i++) {  if (inputString.charAt(begin) == inputString.charAt(end)) {    begin++;    end--;  }  else {    break;  }}if (i == middle + 1) {  System.out.println("That string is a palindrome.");}else {  System.out.println("Sorry, that string is not a palindrome.");    }System.out.println("y/n?");String playagain = in.nextLine();if (playagain == "y")play = true;elseplay = false;}}}
```

## Replies

### Reply by Takeshi Okada

Try this:

if ("y".equalsIgnoreCase(playagain))

Don't use == to compare Strings. All that does is compare reference values. You want equals(): it compares String contents.


---

Original Source: https://www.mindstick.com/forum/12830/java-program-looping-help-i-need-to-restart-the-program-via-a-y-n-input

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
