I am trying to write a regular expression for a text which has both String and number... like abc1234, xyz987, gh1052 etc. And the string usually contains 2 or 3 characters.
What I need is two Strings one containing the text (abc, xyz, gh etc) and other containing number (1234, 987, 1052, etc.). Have written the code below. but doesn't seem to work.
I have a table which contains list of regular expression and its corresponding value.I have to fetch those value and put it HASHMAP where regex as key.I have to compare the each key with the given string(input) and If matches I have to get the corresponding Value for the regex.
I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...
This is the question:
Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:
printStrings("abc", 5);
will print the following output: abcabcabcabcabc
This is what I attempted:
public class printStringsproject { public static void printStrings(int abc, int number) { for (int i = 1; i <= number; i++) { System.out.print("abc"); } } public static void main(String[] args) { printStrings(1, 5); } }
//read the file //make the numbers 1 string line //count the number of repetitiveness in the string for the numbers //display four lowest ones
import java.io.*; import java.util.*; public class Lottery2
[Code] ....
when I run it the array gets sorted but how do i keep the data in other words
what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.
I need to create a regexp, that will do the following:
a,a,a,a,c - matches c,a,a,a,a - matches a,a,a,a,a - doesn't match
I will be using it in Java. In the place of 'a', can be 'b' - they are equal. Also, in the place there can be any other character. This is what i have came up with:
It fails because it matches the 5 a's. I'm quite new to regexp, so I'm not aware of all the possibilities. It matches the 5 a's, because the first if fails, but the second does not. Maybe there is a simpler way to accomplish this? (Also why are the .* necessary in the middle?)
I would like to test whether the first word in a line is is a valid var name (e.g sequence of letters, digits and "_", it may not start with a digit, if "_" is the first char it must be followed by a letter). I tried this simple code:
String namePattern = "_[a-zA-Z0-9]+"; String text = "__c"; Pattern pattern = Pattern.compile(namePattern); Matcher matcher = pattern.matcher(text); "__c" is an illegal var name.
But it returns the string "_c", where it is supposed to return an empty matcher.
private static int getStrength(String pw) { int strength = 0; if(pw.length() >= 8){ strength++;
[Code] .....
This function doesn't seem to work for me. I believe the issue lies in the special character matching. It seems like it always returns true and adds to the strength. But I only want it to add to strength if at least one the following are in the password: *, -, _, ^, !, %
I am using the following regex - [a-zA-Z0-9]{9,18} which means I can use alphabets and numbers with minimum length as 9 and maximum length as 18.It should not take special characters.
It takes values like ADV0098890 etc. but it is also taking ADV0098890[] which is wrong.
With the code below, I am trying to replace all regex matches for visa cards within a given text file.
My first test was with a text "new3.txt" exclusively containing the visa test card 4111111111111111. My objective was to replace the card with "xxxx-xxxx-xxxx-xxxx". This was successful.
However, when modifying the text file to include other characters and text before and after (ex: " qwerty 4111111111111111 adsf zxcv"), it gives mixed results. Although it successfully validates the match, it replaces the whole text in the file, rather than replacing solely the match.
When trying this search and replace with words (rather than a regex match), it does not have this behavior. What am I missing?
import java.io.*; import java.util.regex.*; public class BTest { //VISA Test private final static String PATTERN = "(?s).*4[0-9]{12}(?:[0-9]{3})?.*"; public static void main(String args[]) { try
I have a program in which I am prompting users for integer values to display in a JFrame. I call the method below to load an array with their input:
Java Code:
public String inputAssembly(){ if (!jtfInput.getText().matches("d")){ JOptionPane.showMessageDialog(null, "Input must be of integer value."); } if (jrbFar.isSelected()){ return jtfInput.getText() + jrbFar.getText();
[Code] ....
Regardless of the input, both messages display (invalid input / got it). I've tried debugging so I know that the values are getting entered and read correct, at least to my knowledge. It is a very simple regular expression, only checking to be sure an integer was entered.
I created filters for every column in my Jtable however, some of these columns have more than one word inside of them and my filters will only filter them based on the first word. For example if I had a first and last name in one column, it will filter the table if I enter the first name in my filter text field but it will not filter that same column if I only input the last name. What is a good regex expression to filter any word in any order?
I'm trying to come up with a method that would validate each turn a player makes. For a turn to be valid, it has to only contain numbers from 0 to 3(inclusive) and at least one digit must not be 0. Here is what I`ve come up with so far. For example, with "303" as the number and "101" as the turn, the turn would be valid and my method should return true, but it does not.
public static boolean turnIsValid (String number, String turn ){ boolean rep=false; int pos1=0; char min='0'; char max='3'; while(number.length()==turn.length()&&pos1<turn.length()){
In the above example number 123456789012 is masked to 12XXXXXX01 but the number 55555 remains same as length of 55555 is 5 and we will only mask the number whose length is between 10 to 12 .
I've to return some value as a string and some as a int, how is this possible? Here's my code:
public class Card { public void start(){ String [] suit = {"Spade","Club","Diamond","Heart"}; int [] number = {1,2,3,4,5,6,7,8,9,10,11,12,13};} public String getColour(){ String [] suit = {"Spade","Club","Diamond","Heart"};
[Code] .....
So at the top, i've set it to return value as string because of the King Jack Queen and Ace, but i also have to return as numbers(int). And also i'm using a loop to read all the numbers, is there any other way?
Some of the numbers can be converted from int to string , other cant. My problem is in if (input.length() == 3) and if (input.length() == 4. Basically having problems printing the 3 digit and 4 digit
public static void main(String[] args) { System.out.print("Skriv: "); Scanner console = new Scanner(System.in); String input = console.nextLine(); int firstDigit = 0; int secondDigit = 0; int thirdDigit = 0; int lastDigit = 0;
the number of occurrences of a specified character in a string...i tried to do the program occurrences in a given string and i tried the code as below.
code:
import java.util.*; public class Occurrence { public static void main(String[] args) { Scanner input = new Scanner(System.in);
I'm trying to write a method that returns a number, given an uppercase letter as follows:
public static int getNumber(char uppercaseLetter)
The program is supposed to prompt the user to enter a phone number as a string. The input number may contain letters. The program translates a letter (upper- or lowercase) to a digit and leaves all other characters intact.
My code is below:
import java.util.*; public class PhoneKeypad { public static void main(String[] args){ System.out.print("Enter a string: "); Scanner input = new Scanner(System.in); String phNumber = input.next();
[Code] ....
I am getting these errors: java.lang.ClassFormatError: Duplicate field name&signature in class file Chapter9/PhoneKeypad at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:791) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
Working on my java skills. The is Delimiter function is suppose to return true if there is a delimiter in the string and false otherwise. The main is suppose to call this function and count the number of words in the string:
Here is what I came up with:
import java.util.*; public class NumberOfWordsInString { public static void main (String[] args){ Scanner in= new Scanner (System.in); String s;
[Code] ....
Somehow my method isn't being successfully called by my main and the following error msg was received:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
length cannot be resolved or is not a field
The method isDelimiter(char) in the type NumberOfWordsInString is not applicable for the arguments (char[])
at javaimprovements.NumberOfWordsInString.main(Number OfWordsInString.java:10)
line 10: char ch [] = new char [s.length];
and the main doesn't call the isDelimiter function