Check If A Sentence From User Has Specific Letter?
May 1, 2014
I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.
import java.util.Scanner;
public class secret
{
public static void main(String args[]) {
Scanner sc;
char hidden='a';
String guess;
Basically the requirements are to take a sentence (string of text) and check to see how many times specific words come up and then add to the counter depending on the word.
But I can not seem to get it to add the instances of the goodwords and badwords.
package Strings; import java.io.*; public class SentimentAnalyser { private static String analyse(String text) { int pw = 0; int nw = 0; String[] searchword = { "bad", "terrible", "good", "awesome" };
/** * Auto Generated Java Class. */ import java.util.*; public class Hangman { public static void main(String[] args) { Scanner input = new Scanner (System.in); int guess; boolean revealed[] = {false, false, false, false, false}; String word [] = {"c", "a", "n", "a", "d", "a"};
[Code] ....
I am not sure how to make the program check if the letter entered by the user matches the one in the array. also i am not sure how to make the program run again with a new word.
i am new to programming skills it may be silly question for experience but for me it's new thing. actually i tried a lot but i am facing problem when i trying to take input through Scanner. if i will take input a sentence directly as a string it's working . but when i am trying with Scanner the first word is showing next are not showing
public class Demo2 { public static void main(String[] args) { String s1="hi how are you"; s1=s1.replace('a', 'A'); s1 =s1.replace('e', 'E'); s1 =s1.replace('i', 'I');
[Code]...
this is working properly.
but when i trying with Scanner i am facing problem.
public class Demo2 { public static void main(String[] args) { java.util.Scanner scn= new java.util.Scanner(System.in) String s1=scn.next(); s1=s1.replace('a', 'A');
I have some problem to understand the way to make this:
In my main class a user can save his name in a txt file (and the system initially will add 6 value equals to 0) than he can choose between 6 level and make it.
example of .txt file data:
mario 0 0 0 0 0 0 carl 0 0 0 0 0 0
AT THIS MOMENT i just made other class and they work, is this new one that is hard for me. I'm trying to make a class that:
1- (first method called verificaRisultati) take name_used and level_choosed from the main and go to check in the .txt file if that level before was done right(1) or wrong(0)
and return something like "before you made this level properly" or "before you made this level incorrectly" AND THEN let the user start with the level.
2- (second method called salvaRisultati) at the end of the level i wanna pass the result (correct/incorrect) to another method of this class that will save the value (1 or 0) associated to the user in the right position.
This is the class that i'm writing:
Java Code:
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; public class ResultUsers {
[Code] ....
I really need some hint and some code example because I'm stuck. How I can take exactly the line with the user name? How I can correctly split the line in an array and then read/modify the value for that level?
Why isn't heig ever equal to heightShipArray[count] no matter what letter I type in
String[] heightShipArray = {"A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j"}; boolean trueHeight = true; // checks if height is a letter between a-j/A-J do { Terminal.printLine("Input height with letters A to J");
Ok, so I have to make a program that tells the user to type a sentence and at the end of the sentence a "." must be put to end the program. If a "." period is not entered, it must re-prompt the user to enter a period. On top of all this, the program has to count the number of letters in the sentence. I cant seem to get the while loop working and I cant find anywhere how to make a counter count the number of letters.
import java.io.*; class Sentence //The purpose of this program is to
The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change?
Here is the main class:
public class MorseCode { public static String myInput; public static String[] myMorse; public static String myUserInput; public static char[] myAlph = {'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; public MorseCode()
My assignment is to write a program that will encrypt and decrypt a sentence entered by a user but the encryption is to be random using an array. Can I convert my sentence(string) from char to int then create a random array to encrypt?
import java.util.Scanner; import java.util.Random; /*SentenceEncryptionProgram */ public class SentenceEncryption { string sentence; //sentence entered by user
I've been given an assignment for my Programming Fundamentals class that requires the user to enter a word/sentence to encrypt or decipher, as well as requiring the user to enter a key in which to encrpyt/decrypt the input by.
So a = no shift, b = a shift by 1 and so on.
But I'm completely lost as to what to do, and after searching for Vigenere Cipher topics, they look completely different to mine and (hardly) include prompts?This is my code:
/** * @(#)VigenereCipher.java */ import java.util.Scanner; public class VigenereCipher { public VigenereCipher()
I'm working on a simple 2D Game Framework. Currently it's creating a window, but I'm working on an update method.
I constantly export the framework as a .jar file, and I've added it to the game's build path (using eclipse). I wonder if I can check all classes in the game-project (the project in which I've refecrenced the Framework in) for a specific method (for example update()) and call all found methods with that name from the framework's main class, like this:
public class FrameworkClass1 { private void checkForUpdateMethods() { // Check for update methods on program start } public void update() { runAllFoundUpdateMethods(); // Run all update methods found in the scan } }
I want to do this because it would be a simple way to update and render the game. If the main game-class look something like this:
public class Game { public void update() { // Update the game every time this is ran } }
it will be automatically updated, because it contains a method named update(), instead of naming the main game-class with a specific name etc. It will simply be more flexible that way!
I am using form based, declarative security approach. And, when some user, on login form enters user credentials (username and password), he is being redirected to certain/secured jsp page.
Part of that page content is:Hello <%=request.getUserPrincipal().getName().toString()%> You are able to view this page because you are authorized user.You can see that this is implemented using JSP scriptlet. And this works. I would like to use JSTL instead of scriptlet.
So, instead of scriptlet, I put this JSTL code: <c:out value="${requestScope.userPrincipal.name}"/>, but not getting user's username with it. Basically, I don't clearly understand where and how are these objects/user credentials being stored with Form based JAAS.
I would like on JSP page to check if some user is already logged in. So, if there is logged user to display user's name (also with JSTL).Something like this:
<c:if test="${not empty sessionScope.userPrincipal}"> User <c:out value="${sessionScope.userPrincipal.name}" /> </c:if>
Here I tried with sessionScope but still not getting anything.
System.out.print("To begin, please enter 1 to choose stand tickets or 2 to choose terrace tickets for your party. "); int standOrTerraceTickets = aScanner.nextInt(); while (standOrTerraceTickets != 1 && standOrTerraceTickets != 2) { System.out.print("Invalid input. Please enter 1 for stand tickets or 2 for terrace tickets. "); standOrTerraceTickets = aScanner.nextInt(); }
Okay I thought I had this working properly so that when the user entered anything other than 1 or 2 they would keep getting an error invalid input, however, that only works when the user enters an integer. If the user enters anything other than a number, the program crashes. How does one prevent this from happening?
i am beginner in java and i am making an application in which i want to display menu for 3 different types of users. like when we login i want to check which type of user is this and which menu to show them. for ex. if there is a employee the menu bar has a dropdown which shows activities like fill nomination, see details etc. if it privileged user he is shown a diff menu and if its the admin the dropdown shows some different activities. i want to make it through simple jsp and servlet. i have a table in data base which has types of user predefined with an id how to display that menu according to a specific user.
I have a problem with functions connected to strings.
I have a random String, e.g. "Hello World!" and I have to change every capital Letter into a small letter and vise versa. This alone would be fairly simple, but I have to do it with two other strings.
lowercase= "abcde...z" and
uppercase="ABCDE...Z". Every small letter stands at the very same position as the capital letter, but in the other string.
There should be a letter for letter search in lowercase and uppercase for the letters of "Hello World".
How I could solve the task, however I need a way to search the first string, here "Hello World", according to position. A statement which does: "Give me the letter of position x". This found letter should be able to be stored in a variable or else be able to be used by another statement. And it should be compatible with a for lope.
Example : I have code and name but my code must start with the first letter of the inputed name if the 2 input is match it will be inserted into database
code = "A"001 name ="Angela" = success this will inserted into database
else
code ="B"002 name="Angela" =failed this will not inserted into database
else
code="A"003 name="Andy" =success still accepts the input cause they have diff code number
What I am thinking on this was compare the code the name? if == it will be inserted but how do i get the 1st letter of the input name?
I have a question about how to check for a session as the user goes through different pages. I am using Java beans and EL to pass data from page to page but I cannot figure out how to check for a session on the pages without the use of a scriptlet with an if else statement in it.
I do not want the user to be able to access any pages unless they are logged in. With a scriptlet, I can create a statement that says if session exists show name else redirect to login page.
From what I have read and what some of the wonderful members here have told me, scriptlets are a big no no these days. So, how do I do these without the use of a scriptlet?
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //find selected command String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a proeprties file and if it exists, pull the key and the value back into a panel ....
I made an application and i can send the message/notification to all loggedin users immediately. But the problem is that i am unable to send notifications to a specific user; as an example facebook chat.I am using Servlets 3.0, Spring MVC 3.0, GSon and AJAX Jquery.
I want to send user back to the Login page after idle time of 10 secs. If user clicks again on screen before 10 secs are over, time will automatically reset to new 10 sec and so on...
This program simply adds integers to an ArrayList and then prompt the user if they would like to delete specific numbers that they don't want.
The output that I get when I want to delete numbers like 2 and 4 from 1 2 3 4 5 is 1 2 3 4 5 instead of 1 3 5.
Java Code:
import java.util.ArrayList; import java.util.Scanner; public class AL { // A regular array like int arr[] has to have its size declare before run-time and it's not dynamic which mean it can not grow or expand on its own. static Scanner input = new Scanner(System.in); // You have to use reference types(Integer, Double, Float); not primitive types(int).
Write a program that prompts the user for an input number and checks to see if that input number is greater than zero. If the input number is greater than 0, the program does a multiplication of all the numbers up to the input number starting with the input number. For example if the user inputs the number 9, then the program displays the following sum:
9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 362880
That's the question I'm getting and so far all I've got is
import java.util.Scanner; public class Lab4Q3 { public static void main (String[] args) { int keyboard;
I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...
Java Code:
import java.util.*; import java.lang.*; public class StringCheck{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("please enter a string: " ); String s = input.nextLine();
Write a program that continuously asks for an alphabet letter, and stops when a non-alphabet letter is entered. Then output the number of upper case letters, lower case letters, and vowels entered ....
I am trying to write a specific byte sequence to a specific memory location on a removable storage drive. Does Java allow me a way to do this? I know the dangers in accessing memory, but the memory location of the data that will be written will never change.