Checking SSN Without Regular Expressions

Jun 5, 2012

Prompt user to enter a social security number in the format DDD-DD-DDDD, where D is a digit. Displays "Valid SSN" for a correct ssn, and "Invalid SSN" otherwise.I have it working I am just looking for other ways to solve this with an array maybe or something simpler. I have used if statements here:

public static boolean checkSSN(String social) {
boolean valid = false;
// 9 digits and 2 hyphens. First three characters, 5 and 6, and 8, 9,
// 10, 11 are digits

[code]...

View Replies


ADVERTISEMENT

How To Use Regular Expressions For Integer Input

Jul 21, 2014

I have a program in which I take some characters input from User

using
String inputString=in.next();

How can i restrict user that input should be only char 0 or 1?

If the answer is regular expressions then What Should be Its Regular expressions?

View Replies View Related

Regular Expressions For Range Statements

Apr 1, 2014

I have the following Output

_G7120+1#=K,

_G7132+_G7133#=_G7120,

_G7144+_G7145#=_G7132,

_G7156+_G7157#=_G7144,

_G7168*Z#=_G7156,

_G7180*Z#=_G7168,

_G7192*Z#=_G7180,

_G7204*Y#=_G7192,

_G7192, in 10..15 / 16

X*Y#=_G7204,

X+Y#=_G7133,

_G7145+X#=Z1_a,

Y in 1..15,

Z/Y#=_G7157,

__X in 1..15 / 17 / 20.

From this, I need to extract the statements of variables that do not start with _G . I mean, I need to extract, Y in 1..15 , __X in 1..15 /17/20 but not _G7145 in 10..15 / 16.

I am using regular Expression for this as [^_G]^[A-Za-z0-9_]+ in|ins [-9 -9]..[-9-9] [/[-9-9]..[-9-9]]+

View Replies View Related

Java Regular Expressions - Simple Search And Replace

Mar 1, 2014

I want to do a simple search and replace regular expression of lines. I am very unfamilar with Java regular expressions, and I'm not sure how to do something as simple as what I want to do. I have lines that look like this...

Java Code : access_log /home/%USER%/access_log mh_sh_highlight_all('java');

I want them changed so %USER% changes to a string, such as "cyrus," so they appear like this ...

Java Code: access_log /home/cyrus/access_log mh_sh_highlight_all('java');

The reason I want to use regular expressions is because I want to use the replaceAll method of the java.lang.String object. If I use replace I have to convert my strings into char arrays, and my code becomes bulky.

View Replies View Related

JSP / JSTL :: How To Group Expressions In EL

Nov 12, 2013

In jsp when using EL the parenthesis are not allowed for grouping of expressions. I mean

${(2+3)-1}

is not allowed so if i have to group expressions in EL how do i achieve it?
 
I wanted to do the following in EL

${(a==b && b==c) || (v==r && r==d)}

so how do i achieve this?

View Replies View Related

Java Expressions With Multiple Operators

Jan 11, 2014

Following are the expressions? I tried running them and those are the answers I got. However, I cannot figure out the working.

//c = ++a + a++ - --a - a-- + a * + a/a ; //ans is 10
//c= a* + a/a ; ans. is 1.
//c= a * +3 ; //ans is 30
//c =5+ a* +2; //25
// c= 5+ a* + a/a ; //ans. is 15.

View Replies View Related

Type Conversion In Expressions - Int To Byte

Feb 22, 2015

I am reading a book on Java and we are at a point where it is explaining type conversion in expressions. One of the examples shared has a byte being multiplied by itself and then assigned back to itself ...

byte b;
b = 10;
b = (byte) (b * b);

this is all good and dandy (that is, the code functions properly).

However, I am confused why I need to typecast here! Without the cast, the compiler screams, "Type mismatch: cannot convert from int to byte." Yet I haven't converted to an int?? It appears there was an implicit conversion.

The final value, 100, is clearly within byte's range of -127 to +127 isn't it? So I am lost as to what is the issue here.

View Replies View Related

Save Logical Expressions In Java

Feb 3, 2015

How to save (condion1 & condition2) | condition3 |(Condition5 & condition6) etc in database and how to retrieve it.

View Replies View Related

Evaluating Infix Expressions Using Generic Stacks

May 12, 2014

I am given the task to create a program that evaluates infix expressions using two generic stacks, one operator stack and one value stack.

This is my GenStack.java file:

import java.util.*;
public class GenStack<T>{//T is the type parameter
private Node top;//top of stack
public class Node {//defines each node of stack
T value;
Node next;

[Code] ....

I'm having trouble with the eval and apply methods. The eval method doesn't appear to pickup ')' characters, like it doesn't even see them.

View Replies View Related

Integer Variables - Which Three Logical Expressions Are Equivalent To Each Other

Apr 12, 2014

Assuming that x, y, and z are integer variables, which of the following three logical expressions are equivalent to each other, that is, have equal values for all possible values of x, y, and z?
 
(x == y && x != z) || (x != y && x == z)
(x == y || x == z) && (x != y || x != z)
(x == y) != (x == z)
 
None of the three
 
A. I and II only 
B. II and III only 
C. I and III only
  D. I, II, and III

I selected B, but got it wrong. I really think I need understanding boolean logic. The correct answer says something else but I don't get the logic. Here is the correct answer:

Answer Key : The following model answer has been provided to you by the grader. Carefully compare your answer with the one provided here.

Expression III is the key to the answer: all three expressions state the fact that exactly one out of two equalities, x == y or x == z, is true. Expression I states that either the first and not the second or the second and not the first is true. Expression II states that one of the two is true and one of the two is false. Expression III simply states that they have different values. All three boil down to the same thing. The answer is E.

In exercise 4, I get the same problem:

The expression !((x <= y) && (y > 5)) is equivalent to which of the following?

A. (x <= y) && (y > 5)
B. (x <= y) || (y > 5)
C. (x >= y) || (y < 5)
D. (x > y) || (y <= 5)
E. (x > y) && (y <= 5)

Exercise 4
ABCDE
Incorrect
Score: 0 / 1
Submitted: 2/10/2014 8:21pm
Your answer is incorrect.
Answer Key

The following model answer has been provided to you by the grader. Carefully compare your answer with the one provided here. The given expression is pretty long, so if you try to plug in specific numbers you may lose a lot of time. Use De Morgan's Laws instead:

!((x <= y) && (y > 5))
 !(x <= y) || !(y > 5)

When ! is distributed,
&& changes into ||, and vice-versa

(x > y) || (y <= 5)

View Replies View Related

Simple Form Of Doing Groups Of Expressions In One Line?

Jun 13, 2014

I am trying to put all this in one line - new DefaultTableModel(0, INT HERE) - there is a way?

List<ArrayList>valores=new ArrayList();
...
ArrayList valorPrimeiro=valores.get(0);
int primeiroTam =((ArrayList)valorPrimeiro.get(0)).size()+1;
defaultTable=new DefaultTableModel(0, primeiroTam);

View Replies View Related

JSP :: EL Expressions - Find A Place Where Values For Status Is Being Set / Assigned To

Feb 4, 2014

I have a web application project built in Spring MVC 2.5. There are some EL expressions which are used in JSP as below:

${status.value}
${status.expression}
${status.errorMessages}

But, I coudln't find any place in Java/JSP where the value for status is being set. What could be the possible place where the values for status is being set.

As the code is client specific, so, I couldn't paste the specific code over here but I have searched in whole workspace i couldn't find a single place where values for status is being set/assigned to.

View Replies View Related

Conversion Between Primitive Data Types - Mixed Mathematical Expressions

Aug 6, 2014

How I'm supposed to write out the statement.

I am fairly certain that I should be making variable "b" and "c" a float. But beyond that I'm confused.

uploadfromtaptalk1407333378833.jpg

View Replies View Related

How To Check Regular Expression

Aug 25, 2014

I have to match pattern like 76XYYXXXX mean x can be 4or 5 and Y can be 6 or 7. All x and y should be same .i.e. 764664444

View Replies View Related

N-sided Regular Polygon

May 8, 2013

I'm working on is to create a program to display an n-sided regular polygon and uses two buttons named +1 and -1 to increase or decrease the size of the polygon. Also enable the the user to increase or decrease the size by clicking the right or left mouse button and by pressing the UP and DOWN arrow keys. So, first off I'm just trying to figure out how to display an n-sided polygon. I have some of the other components started, but I'm just trying to focus on getting this to work.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Polygon;

[code]....

View Replies View Related

Simple Regular Expression

Jan 17, 2014

I am currently enrolled in my first Java class. I have taken C# in the past so I've messed with some regular expressions, but I am having trouble finding a good website for Java. Is the syntax the same?I want to create a regular expression to only allow the following characters: c C f F [and any 1-3 digit number].

View Replies View Related

How To Use Regular Expression Using Pattern

Mar 16, 2015

I have a string "We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle" I need to replace the numbers based on the below condition.
 
if more then 5, replace with many
if less then 5, replace with a few
if it is 1, replace with "only one"
 
below is my code, I am missing the equating part to replace the numbers

private static String REGEX="(d+)";
  private static String INPUT="We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle";
  //String pattern= "(.*)(d+)(.*)";
  private static String REPLACE = "replace with many";
  public static void main(String[] args) {
  // Create a Pattern object

[Code]...

View Replies View Related

Java String Regular Expression

Apr 17, 2014

I have written below regex for two lines.

String LN1Pattern = "^((?=.{1,35}$)(/([A-Z]{1,5})(|(//[a-zA-Z0-9]+))))$";
System.out.println("/ABC//FGhiJkl012345".matches(LN1Pattern));
 
String LN2Pattern = "^(|((s+(//[a-zA-Z0-9]{1,33})){1,2}))$";
System.out.println("".matches(LN2Pattern));

s+ is a newline character.

But when I combines both as below, its not giving me expected result.

^(((?=.{1,35}$)(/([A-Z]{1,5})(|(//[a-zA-Z0-9]+))))(|((s+(//[a-zA-Z0-9]{1,33})){1,2})))$

For string "/ABC//FGhiJkl012345

//abCD01EF02" - returns False. Expected is True

I think there is some problem in lookahead placed.

View Replies View Related

Performing Regular Expression - Valid Last Name

Feb 4, 2015

I have some problems about performing regular expression. In the following code, the output as a result is being "valid last name". But in my opinion, it should be "invalid last name". Because "Doe" has not any space, apostroph or any hypen. Look at the regular expression statement: "[a-zA-Z]+([ '-][a-zA-Z]+)*"
 
package deneme; 
public class Deneme {
public static void main(String[] args) {
String lastName = "Mc-Something"; // Mc-Something 
if(!lastName.matches("[a-zA-Z]+([ '-][a-zA-Z]+)*"))
System.out.println("Invalid last name");
else
System.out.println("Valid last name");
}
}

I know that the asterisk qualifier means character(s) in any number.(Is this wrong?) So for "Mc-Something", 'M' corresponds to [a-zA-Z], 'c' corresponds to +, - corresponds to [ '-], 'S' corresponds to [a-zA-Z], "o" corresponds to +, and finally "mething" corresponds to *, doesn't they? But for "Doe", there is no any space, apostroph or hypen.

View Replies View Related

Inserting Into A Regular Binary Tree?

Nov 26, 2014

I know that for a binary search tree the insert() method is easy. You just kept comparing the values of the nodes, and you would know whether to go left or right depending on the value of the node.However, I am stumped when trying to figure out how to add a node into a normal binary tree where you just keep adding the nodes to the leftmost side, regardless of value.Here is my attempt at the insert() method:

public class RegularTree extends BinaryTree {
public CompleteTree() {
super();
}

public void insert(Comparable item) {
if(this.isEmpty()) {
this.setRoot(new TreeNode(item));
return;

[code]....

View Replies View Related

Area Of Regular Pentagon - End Result

Jul 17, 2014

I am doing exercises which has to do with the area of regular pentagon.

(Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is :

I have checked errata on their page and they did not list the type-o under the final result.

Errata link [URL] ....

their result is
Enter the number of sides: 5
Enter the side: 6.5
The area of the polygon is 74.69017017488385

and mine is Area of regular pentagon is 72.69017017488385

is it a code error?

import java.util.Scanner;

public class AreaOfAregularPolygon4_5 {
public static void main (String[] args){
//Initiate scanner and use the input
Scanner input = new Scanner (System.in);
System.out.println(" Enter the number of sides in polygon");

[Code] ....

View Replies View Related

Regular Expression In Java Which Allow Only Numbers

Nov 28, 2013

I need a regular expression in java for phone number which that does not allow any character special character only numbers should be allowed.. My sample program is
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class c {
  public String removeOrReplacePhoneNumber(String input) {
  if (null == input)
  return input;

[Code] ....
 
but this is allowing characters like a,b,c..

View Replies View Related

I/O / Streams :: Parsing Logs Using Regular Expression

Dec 1, 2014

I am new to java coding. so, reading the log file using java code.

1) I wish to parse a file, and find a value for variable e.g. [StorageVersion].
2) After finding the value, it will be pushed to database.

Following is the code that i have written till now.

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.regex.*;

[code]....

1) I don't know what regular expression can i use.
2) I want a line to check that preceding line should have //StorageVersion .
3) n then i will check any string between := K[' and '];. From above log file "'706146.0.22106932'" is the value that i am looking for.

View Replies View Related

How To Split A Text Looking For Values With Regular Expression

Aug 6, 2014

I have to read a text looking for value related to certain variable. The variable are always DE plus identifier from 1 to 99 or DE plus identifier from 1 to 99 and SF plus identifier from 1 to 99. The value can be alphanumeric. How can I get these values? As a start point, I try to use split("DE") but I can get something that is wrong if there is "DE" inside the text that doesn't me interest. I look for scanner but it doesn't work. I guess that there is some way, maybe using regex but I am completely lost ( I have never used regedix before and I am in rush to fix this).

Basically, the text is similar to the below where DE means data element and sf sub field. Some data elements have sub fields while others don't. I guess that there is a way to split with something like DE+anyNumberFrom1To99 = theValueAimed in some array and DE+anyNumberFrom1To99+,+SF+anyNumberFrom1To99 = theValueAimed in other array.

DE 2, SF 1 = 00 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 1 = 0 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 4 = 1 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 5 = 0 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 6 = 11 SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 7 = 90x SOME TEXT THAT DOESN'T INTEREST ME
DE 22, SF 7 = 12ab SOME TEXT THAT DOESN'T INTEREST ME
DE 99 = 1234 SOME TEXT THAT DOESN'T INTEREST ME

View Replies View Related

Regular Expression In Java For HTML Pages

Feb 18, 2014

I need to parse an html web page to extract specific information from the tags in Java. For example,

<b>Species </b> Strain </td>

I need to look for the Strain info (Strain is variable in length) in the page. The whole web page is stored as a huge string. I need a regular expression that can identify all the Species and retrieve their corresponding strain info. how to do this or can propose some clever string manipulation methods in Java.

View Replies View Related

Specific Regular Expression - Split A String

Mar 3, 2014

Regular expression which I want to use to split a string. The string could look similar to this:

"a = "Hello World" b = "Some other String" c = "test""

The String is read from a file where the file contents would be:

a = "Hello World" b = "Some other String" c = "test"

After splitting I would like to get the following array:

String[] splitString = new String[] {"a", "=", ""Hello World"", "b", "=", ""Some other String"", "c", "=", ""test""}

I know I could just write a simple text parser to go over the string character by character, but I would rather not do it to keep my code clean and simple. No need to reinvent the wheel.

However, I just cant seem to be able to find the right regular expression for this task. I know that a RE must exist because this can be solved by a finite automaton.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved