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


ADVERTISEMENT

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

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

Post Integer Variables In Next Class

Jan 31, 2014

I write a small program. I want post my integer variables in the next class. Here a code(I wanna change answer color):

Main class(pagrindine.java):
import java.awt.*;
import javax.swing.*;
import java.awt.event.*; 
import javax.swing.event.*;
//Mokinio rinkinukas su skaiciofke kur gali keisti atsakymo spalva, pabandyti sukurti uzrasu knygute.
 
[code]....

So, I want to post variables r,g,b from class slideris.java in the pagrindiness.java.

View Replies View Related

Arithmetic Methods Whose Main Method Holds Two Integer Variables

Jan 15, 2015

a. Create an application named ArithmeticMethods whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayNumberPlus10(), displayNumberPlus100(), and displayNumberPlus1000(). Create each method to perform the task its name implies.

b. Modify the ArithmeticMethods class to accept the values of the two integers from a user at the keyboard.

View Replies View Related

Logical Error With Else If Statement?

Aug 12, 2014

I was almost finished with my program when I noticed I had a big logical error. At the very beginning of my else if statements I would jump down to my else statement.

Java Code:

import java.util.Scanner;
public class InternetServiceProviderNew
{
public static void main(String[] args) {
double packageA, packageB, packageC, extraA, extraB, userHours, aHours, bHours, cHours, userCharges;
packageA = 9.95; packageB = 13.95; packageC = 19.95; aHours = 10; bHours = 20;
String userPackage, A, B, C ;

[code]....

View Replies View Related

Getchar Equivalent In Java

Aug 1, 2014

I was just wondering about the equivalent of c function getchar() in java? I am trying to assign letters to array elements through input stream. A simple code in java that matches this code:

int;
char array[];
for(i=0; i<10; i++){
array[i] = getchar();
}
for(i=0; i<10; I++){
putchar(array[i]);
}

View Replies View Related

How To Get Java Equivalent Of C++ Constant

Jun 10, 2014

How to make sure that a variable passed to a method isn't altered by the method? I know in C++ you can do something like

void aMethod(const Object &item) {
........
}

I know that you can stop a variable from being reinitialized in java by doing this

void aMethod(final Object item) {
.........
}

However, that won't stop it from calling a setter on the item or changing something in it. Is there some other keyword out there that can do this? I just found that java DOES recognize the const keyword but that it really is useless.

So, any practical way that const can be further approximated in java beyond using final?

View Replies View Related

Stuck With A Logical Error

Jan 23, 2015

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;

[code]....

Total IS those numbers. But question[10] will not cooperate with me and it's getting a bit aggravating as I can't find a logical reason for it to be doing that.how to perhaps lock the value of total and sTotal after 10 button clicks from any?

View Replies View Related

Match RegEx Equivalent Of Contains?

Oct 4, 2014

In a code im writing I was curious as to instead of

contains(".")

I wanted to use

matches(" ") method instead but really having issues with the regex

I have tried //. as well as ^[.] but they give me errors.

I am just trying to match a period but was curious as to what the form was. I read a good amount of materials and seemed simple but getting errors.

View Replies View Related

Truth Table For Logical Operators

Nov 11, 2014

I've created a truth table for logical operators. Now I'm supposed to alter the code so the table prints 1's and 0's instead of true or false. Here's a bit of the original code - just the header and the first line of the table.

System.out.println("p q AND OR XOR NOT");
System.out.println();
boolean p, q;
p = true; q = true;
System.out.print( p + " " + q + " " );
System.out.print( ( p & q) + " " + ( p | q) + " ");
System.out.println(( p ^ q ) + " " + ( !p) );

All of my ideas involve using an if-then statement, but that would be all kinds of inefficient and unwieldy, I think.

View Replies View Related

How To Display Equivalent Binary Value In Java 1.5

Jan 8, 2014

While am trying to display a numerical digit from an equivalent binary value of integer data-type its working fine in JAVA 1.7 but not in JAVA 1.5

View Replies View Related

Nested If / Else - Cannot Determine Logical Mistake

Jan 5, 2015

The title says already where my difficulties are. I forgot to say, the "S" printing part works, but why the others doesn't. To make it more clear:

java Monoton 1 3 3 4 & java Monoton 1 3 4 1

=> nothing (my output)

I forgot to notice, with 1 3 3 4 as parameters it jumps out at if (b < c), which is expected. but it jumps out of the whole if instead just run the else part. that's the essence of my problem.

The Exercise:

=> The program should print the following letters;

S, if every number is true bigger than the before,

M, if every number is bigger or equal than the before,

N in the other cases

Examples (from the exercise)

=> java Monoton 0 1 2 4

S

=> java Monoton 1 3 3 4

M

=> java Monoton 1 3 4 1

N

The Exercise should done without the use of logical operators or other combined requirements.

Java Code:

public class Main {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = Integer.parseInt(args[2]);
int d = Integer.parseInt(args[3]);

[Code] .....

View Replies View Related

Printing Decimal Equivalent Of Binary Number

Feb 28, 2014

This problem is from Java . It asks me to convert a binary number in to decimal. How to program this in java? I am not able to find an effective algorithm to convert in to Java.

View Replies View Related

Equivalent Arrays - Comparing 2 User Inputs To Determine If Same

Mar 4, 2015

I have been stuck on this for the past 2 hours, basically we have to compare user input, put user input into an array and compare for equivalency. An example of the program:

Array 1: 1 2 3 4 5 6 7 8
Array 2: 1 2 3 4 5 6 7 8
Array 3: 1 2 3 4 5 6 7 8 9
Array 4: 1 2 3 4 5 6 7 8

Array 1 & 2 are equal
Array 1 & 3 are not equal
Array 1 & 4 are not equal.

This cannot be done by importing Java.util.Array at all!! (my research only find this to compare arrays ) which is why I am having trouble starting off. My code thus far:

import java.util.Scanner;
public class Lab07b {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Integer 1:");
int a = input.nextInt();

[Code] .....

View Replies View Related

Validate Names And Test Scores - Logical Error

Oct 14, 2014

I am working in the field of validating data. I need to validate names and test scores and i keeping getting errors in my code. I keep tracing back all the errors and now I am stuck at a logic error. It is giving me a the validate sentence over and over even when i type stuff in. I have searched up how to do the .equals to a string but it doesn't give me a accurate enough to my problem.

import java.util.Scanner;
public class P5A
{
public static void main (String args[]) {
System.out.println( "Always Show" );
Scanner reader = new Scanner(System.in);

[Code] .....

View Replies View Related

Is It Possible To Scan Logical Gates From Hand-drawn Image

May 12, 2015

I am thinking of a project for my university the teachers liked it but I am not sure if its even possible.I am trying to make an andriod app. What I want to do is take a picture of a hand drawn logic circuit (having the AND, OR, NOT ... gates) recognize the gates, and make a circuit in the moblie and run it on all possible inputs.

For this I will have to make a simulator on mobile, that I dont think is the hard part. The problem is how could recognize the gates from a picture. Example of logical circuit is attached ( assume its hand drawn )..I found out that theres a edge detection plugin in java but still I dont think its enought to recognize the gates. Please share any algorithm or any technique or tools that I can use to make this thing.

View Replies View Related

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 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

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

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

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

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

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







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