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 following Cipher Code and test for it. But I am getting following exception.
Java Code:
java.lang.IllegalStateException: Cipher not initialized at javax.crypto.Cipher.checkCipherState(Cipher.java:1672) at javax.crypto.Cipher.doFinal(Cipher.java:2079) at com.anjib.util.CipherUtil.encrypt(CipherUtil.java:67) at com.anjib.util.CipherTest.testEncryptDecrypt(CipherTest.java:23) mh_sh_highlight_all('java'); Java Code: public class CipherUtil { private static Logger log = Logger.getLogger(CipherUtil.class);
Write a class encapsulating the concept of a course grade, assuming a course grade has the following attributes: a course name and a letter grade. Include a constructor, the accessor and mutator, and methods toString and equals.Write a client class to test all the methods in your class.
how to test and finish the toString and equals method in this code ?
package labmodule7num57; import java.util.*; public class LabModule7Num57 { // Constructors// private String name; private String letterGrade; public LabModule7Num57 (String name,String letterGrade) {
InputStream inputStream = null; OutputStream outputStream = null; try { URL url = new URL(imgfm); inputStream = url.openStream(); outputStream = new FileOutputStream(imgto); byte[] buffer = new byte[2048]; int length;
[Code] ....
I have several pic to download (e.g 30) however, the code work for some pic (workable for a random number of pic, sometimes workable for 10 pics but sometime can only download 1 pics).
I try to input several println code to found out the problem. finally i found that all the code stop (it's stop as when i use debug process in eclipse, it get no respond) and the final appear code under console is:
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 am doing a project to generate three names of fruits. When I take out my switch code the numbers generate randomly, but when I added the switch code back I kept getting three instances of "Bars" as if the random numbers all became 5.
public static void main(String[] args) { System.out.println("Enter the amount of money you would like to gamble."); Scanner keyboard = new Scanner(System.in); int num1; int num2; int num3; int money; money = keyboard.nextInt();
I worked on this simple client server chat app and it worked now for my project i needed to work on client server audio streaming broadcast but i dont really know much bout audio api and methods on java...
I am creating a simple code in Java that replaces all tabs the user inputs with '*'. However, I am doing something wrong and I am not sure what. Here is what I have so far in Eclipse..
import java.util.Scanner; public class ReplacingTabs { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = ""; String s2 = "";
[Code] .....
There is an error with the s2 in the line String s2 = s.replace(' ','*');
I think I need to add String s2 to the loop but I am not sure how..
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'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();
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();
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 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 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 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 was a bit confused of the code generated by the Axis2 Code Gen.
I have created a logIn(String username, String password) method in my service and used Axis2 Code Gen to generate the Stub.
I try to access the logIn method from my Client using the Stub like below:
TestServiceStub stub = new TestServiceStub("http://localhost:8080/axis2/services/TestService"); String test = stub.logIn("user","pass").
but instead of UserName and password as the parameters, the Stub created a Login object as the parameter for the logIn method. like the one below:
stub.logIn(Login login1);
I wanted to try the logIn method by providing a static userName and password but it seems impossible because the Stub changed the parameter for the logIn method.
The code here I have works fine if I just want to ask the user to enter four digits: //java application that asks user to input binary numbers(1 or 0) and convert them to decimal numbers import java.util.Scanner; //program uses class scanner public class binarynumber{
//main method that executes the java application public static void main(String args[]){ //declares variables
int digit; int base=2; int degree; double decimal; int binary_zero=0; int binary_one=1; //create scanner for object input
[code]....
The thing is, I want the java application to input more than four digits for the user and I want it to loop it manytimes f until the user ask it to stop.