Input String And Test Whether Or Not It Is Palindrome
Feb 6, 2015
I have to write a program that inputs a string and tests whether or not it is a palindrome. This worked fine, and now I want to make it so I continually enter strings until I tell the program to stop.
The code below compiles just fine, but it doesn't do what I want. Why it doesn't work how I think it should work? (Typing in STOP does not make the program stop.)
Here is the code
import javax.swing.JOptionPane;
public class PalTest {
public static void main(String[] args){
String S="pony";
while(S!="STOP"){
S=JOptionPane.showInputDialog("Enter a string (STOP to terminate):");
I have to write a program that inputs a 5 digit integer from the keyboard and prints if the input number is a palindrome or not. I got it to work, but when my result prints it says "0 is a palindrome" or "0 is not a palindrome". How can I get rid of the 0 and replace it with the number input by the user?
import java.util.Scanner; public class Palindrome { public static void main(String[] args) { int number; int digit; int temp;
I'm supposed to use stacks (implemented with an array) to check to see if a string is a palindrome. I've finished all my classes and methods, but I'm getting an ArrayIndexOutOfBoundsException when I try to run my demo program.Here are my classes:
public interface Stack { // Creates an empty stack public void initializeStack() // Returns true if the stack is empty, returns false otherwise public boolean isEmpty(); // The stack can never be full, so always return false public boolean isFullStack();
The program is to accept a string and display all the palindrome words(the words that are same even if they are reversed-------->mom,madam,malayalam etc.)in the string.
I need to solve this program urgently.
There are no syntax errors but after typing in the sentence,no output is displayed. This is my program....
import java.util.*; class palindrome_test { public static void main(String args[]) { Scanner in=new Scanner(System.in); System.out.println("Enter a sentence"); String usersInput=in.nextLine();
I am trying to test the instanceof keyword. To do this, I've made a method with a simple logical test like so:
Java Code:
Vehicle vehicle1 = new Vehicle(); public void Type(){ if (vehicle1 instanceof Vehicle) { System.out.println("Type = Vehicle"); } else if (vehicle1 instanceof Car) { System.out.println("Type = Car"); } else if (vehicle1 instanceof Truck) { System.out.println("Type = Truck"); } } } mh_sh_highlight_all('java');
I wanted to try implementing it into the class definitions for Vehicle, then extend that to Car and Truck, but I'm not sure how to use this test in a general case.
The only way this method works is if I set the test to specifically accept a specific object as a parameter.
I want to test multiple objects, but I'm not really sure how else to do this without simply copy-pasting the logical test multiple times and changing the respective objects that are used as parameters.
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:
calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale
Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F
System.out.println("Enter the first score"); test1 = keyboard.nextDouble(); System.out.println("Enter the second score"); test2 = keyboard.nextDouble();
I have been creating a Java program to track inventory using an array. I need to add a search function to it to take a term, input through a text field, and locate a matching instance within the array. How can I code a JButton to grab test input from a JTextField and search for it within the array then display the corresponding information? I also need to add buttons to add and delete items as well.
I wrote a couple classes and am trying a test driver but it is having an error I do not know how to solve.
Student Class:
public class Student{ private Course[] courseList; private static int numCourses; private final int maxCourses; public Student(int max){ maxCourses = max;
[Code] .....
Error: javac tester.java tester.java:6: error: cannot find symbol one = new Course(name); ^ symbol: variable name location: class tester 1 error
Same issue, just only one error as there is only one line. It seems like it does not accept my parameters as it cannot find symbol.
I forgot to put the "" in the brackets, it's been a month since I have looked at any java and made this simple mistake.
I have the following code to check for five characters palindrome but it always give me incorrect answer that if i have a word like radar the answer it isn't a palindrome. and if i changed any thing in the code i got either stack overflow or index out of bounds exception
The code is as the following
import java.util.Scanner; public class Palindrome { int first =0; static int n; int last = 4; int y = 0; public static void main(String [] args)
I recently have tryed to make a java code that reads words and say if its palindrome or not. I want to fix two things but unfortunately i can't do it on my own.
1st thing that i want fix is that when i run the code i have to press 2x times enter..and i dont know why?(i want one time to press it when i write the text)
2nd thing that i want to fix is that when you run it you can put as many words as you can..only when you write "END" the code must ends.
So unfortunately my code runs only for 1 time.(one word)
My code:
class test { public static void main(String args[]) { System.out.print( "#Enter text : " ); String text = BIO.getString(); String reverse = BIO.getString(); int length = text.length();
I cant figure out something in my code. I have to check whether given doubly linked list is palindrome or not. If it is palindrome it should print 1 , if not -1. My code has no errors but it always prints -1. I tried debugging but first comparisongives always false and function cant reach to else statement.
Are there any logical errors or i cant do right way of comparison?
import java.util.Scanner; class DLLNode<E> { protected E element; protected DLLNode<E> pred, succ; public DLLNode(E elem, DLLNode<E> pred, DLLNode<E> succ) { this.element = elem; this.pred = pred; this.succ = succ;
I'm in the process of writing a program that determines if a number is a Palindrome or not. I'm not allowed to use strings and am required to use the getSize method shown below. I believe my issue that I'm having is that the "num" is not being called in the getSize method, and therefore not running the while loop, or at least that is what I believe is the issue.
import javax.swing.*; public class getSize{ public static void main( String[] args ) { int num; num = Integer.parseInt (JOptionPane.showInputDialog ( "Please input a number" ));
I am trying to figure out stacks and queues and was trying to get this Palindrome program working so I could then play with it and use the Java visualizer site but for some reason the program isn't working correctly. It always states that the input is a palindrome no matter what the user input is.
The book that I got the code from is a little old so I changed a couple small things that I thought needed updating like adding scanner. I wanna use one with a custom array based stack and queue class rather than the java.util.Stack and Queue interface, just for understanding stacks and queues better hopefully.
import java.util.Scanner; import javax.imageio.IIOException; public class PalTest { public static void main(String[]args) throws IIOException { Scanner scan = new Scanner(System.in); PalindromeTesting x = new PalindromeTesting();
I am trying to create a program that reads a sentence, such as: "abba is running to the radar" scans this sentence, and then prints out all the palindromes. I am running into issues with my arrays and for statements. Here is my code:
static String palindrome, backwardsLower, palindromeLower, palindromeClean, backwards2, backwards = ""; static String[] words; static int counter; public static void main(String[] args) { palindrome = JOptionPane.showInputDialog("Please enter a phrase. " +
[Code] ...
I am aware that there is a few "useless" variables in there at the moment, I will clean them up (as well as some useless statements, I see those too). The issue comes at about line 17. The variable backwards REMOVES all the spaces from the array, so when it comes time to compare the strings, it is comparing individual words to the ENTIRE string, thus no words will ever be a palindrome.
I trying to get this code to get user input instead of reading from a hardcoded array. I'm getting compile errors while trying to get user input. Here's some of the code:
I want to find the prime palindrome numbers less that a given number by my program. Here is my code, I am trying to find the method to solve the errors when I compile it. It said variable a might not have been initialized in line 41,62,86.
import java.util.Scanner; public class Lab5{ public static void main (String[] args){ System.out.println("Please input a number"); Scanner Input=new Scanner(System.in); int num = Input.nextInt();
I have to take a users input. The general gist of the problem is I want to convert a decimal number entered by the user inputs into it's binary equivalent....the conversion part I know how to do.
I'm stuck at the user input phase. If the user inputs a decimal number within the correct range (lets say between 0-5000 for this example) the conversion goes ahead as planned and the program outputs on the screen the binary equivalent.
If on the other hand the user inputs a number outside of this range ... OR a String OR and empty space, an error message is given and the user is asked to try again. I don't know how to handle it if the user enters the different types...int or String.
I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions
Do you like donuts? and What did you have for breakfast?
Here is the code this is in Bluej :
import java.util.Scanner; public class FortuneTeller { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Welcome to Fortune Teller");
I am trying to make a program in which first I am entering number of charachters and then in nextline their is exactly that number of characters should be enter after than program should stop taking input from console..this is I have try so far
I am working on a program where I want the user to input multiple classes.
One int, and one String.
Can this be done? if so, how?
I have a tried to get input from both, like in the code below:
Java Code:
import java.util.Scanner; public class ForumFlowchart { public static void main(String[]args){ //Creating scanner. Scanner input = new Scanner(System.in); //Get information about job System.out.println("Type in Int"); int i1 = input.nextInt();
[Code] ....
If I keep my input in the same class, I get the error "Can not cast int to string". My question is, it is possible to get an input from both an Int and a String in the same program?
I am supposed to write a program on PuTTY using UNIX (I have Windows 8), but I am not comfortable with it yet, so I am using Java through NetBeans (IDE 7.4).
The program has to follow these instructions (ignore the Linux part of the instructions, the rest is in bold):
Write a program on the Linux system using the putty utility. The program should get strings of data from the command line (that is, look for the data in the "args" array of strings). Use a loop to convert each of the strings in the array into a double and add the number to a total. Print the total after all of the strings have been processed.
The program will use try-catch to catch any error that occurs. If an error occurs, the program will print a message saying that the error occurred. The program can end at that point.
You should create the Java program using the nano editor. The input data should be a list of numbers on the line that runs the program.
The problem so far is that I keep getting an error when converting a String value into a new double value. I have yet to code the try-catch method in my program
Java Code:
import java.util.*; public class Program13Strings { public static void main(String[] args) { Scanner scan = new Scanner (System.in); System.out.println("How many lines of data do you wish to enter?"); int size = scan.nextInt();
[Code] ....
*NOTE: right where my code says double newDouble = Double.valueOf(newResponse); is where the error is occurring.
*ERROR: Exception in thread "main" java.lang.NumberFormatException: For input string: "abc"
at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1241) at java.lang.Double.valueOf(Double.java:504) at program13strings.Program13Strings.main(Program13St rings.java:21)