My program basically has 2 executeQuery statements. Based on the result of the first sql query the 2nd sql query gets executed (I intend to use if else ladder). The control executes the first query but never executes the second one.
I am trying to execute the following method: This method takes a delivery date as one of the arguments and a list of calendar holidays as another argument. If the delivery date is present in the holiday list, I will add 1 day more to the delivery date and check again if the new delivery date is part of holiday list.
Issue is that the last 3 statements before 'return' are getting executed multiple times though there is no for or while loop. Why they are getting invoked multiple times.
@SuppressWarnings("rawtypes") private String fetchNextWorkingDay(String sDeliveryDate, Element eleCalendarDayExceptions, SimpleDateFormat sdf, Format formatter) throws Exception { System.out.println(""); System.out.println("Inside fetchNextWorkingDay method"); System.out.println("Del Date to compare is "+sDeliveryDate); Boolean isDateSet = true;
I have an FX application which invokes a REST JSON webservice. It works perfect if I run it standalone. But if I try to run it over browser, it throws java security exception.
It also works fine in web if I comment some lines that invokes the webservice (code that calls the webservice using jackson.)
Java version used is JDK 1.7u67 IE plugin version : 7.0.670.1
Error log : java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers") at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source)
So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.
So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?
import java.util.Scanner; public class Variable { static Scanner zcan = new Scanner(System.in); public static void main(String[] args)
I'm trying to run an if statement with an input condition and here is my code.
import java.util.Scanner; public class App10A { public static void main(String[] args) { Scanner fun = new Scanner(System.in); System.out.println("What's your name?"); String name = fun.nextLine();
[code]....
When the computer asked me "What's your name?", I typed in Victor, then the result turned out to be "Oops, try again!".I typed in Victor (without parenthesis) and "Victor" and both gave me the negative results.What exactly should I put in in order to get "This is the result I wanted!" ? how should I modify my code in order to get "This is the result I wanted!" when I put in Victor (without changing the equal sign)?
How do I use a variable in an if statement to return a public void method from another class? I've tried:
System.out.print("select 1 - 6: "); Scanner myScanner = new Scanner(System.in); myScanner.nextInt(); if (myScanner.nextInt()==1) { carSelection colour = new carSelection(); colour.carSelection();
The method colour in class car selection is just 4 print line statements? I've // out the if statement to see if it is correctly calling the method and displaying the data and it is?
I'm having a problem where an if statement isn't working. In the Person class boolean olderThan ignores my if statement so it always returns false and I just don't get why that's happening.
import java.util.Calendar; public class Person { private String name; private MyDate birthday; public Person(String name, int pp, int kk, int vv) { this.name = name;
In the program below I populated three arrays: student id, name, and GPA. The findStudent() method attempts to match users input with the input stored in the studentID array using an if/ else statement. When I use the if/ else statement the else always executes regardless if the IDs match? I am trying to get JOptionPane.showMessageDialog(null, "Incorrect entry"); to print only if the IDs don't match.
Java Code:
//FILE: StudentIDArray.java import javax.swing.*; //Used for the JOption dialog boxes import java.util.*; //Used for Scanner input public class StudentIDArray { boolean nameFound = true; final int numOfElements = 2; //Final int to control to loop for data
I have this JAVA written but I can't get the parameters for the if statements right.
import java.util.Scanner; public class myFirstJAVA { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter command: "); String text = input.nextLine();
I am making a simple calculator. I want the user to input either string "add" or "subtract" and then it will take two numbers and either add or subtract them. I cannot get the if statement to work with a string!
import java.util.Scanner; public class newcalc { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter add or subtract");
I'm trying to make a test on java. So far I'm on Question 1 and I'm having this issue. The if else statement won't allow me to add to the score.
class ExamEngine { static CinReader Cin= new CinReader(); static int Score=0; public static void main(String[] args) { System.out.println("Type in your name."); String name=Cin.readString();
[Code] ....
If I remove the "Score++;" bit, everything is fine. But I need to add to the score when they answer a question right. However, with "Score++;" there, I get this issue: 'else' without 'if'.
Note that this cannot be multiple choice, so that's why I'm using if-else, because I don't think a case system would work here.
Is there a way I can make this work while adding to the score?
I've done a basic login GUI for a application, a user enters their name and address and clicks register, a four digit pin is then randomly generated, the pin and name and address are all added to an object of the MemberDetails class , this obj is then added to an array list.
returning customers can then enter a previously generated pin and either get a welcome back message or an invalid pin message.
my issue if i register two new users and get their generated pins, that on the returning members screen it will only show the welcome message for the second new customer i created and not recognizing the first customers pin. heres my code:
taking in new customer details, generating pin , adding obj to arraylist
int randomPIN = (int) (Math.random() * 9000) + 1000; members = new MemberDetails(); members.name = nameNew.getText(); members.address = addressNew.getText(); members.pin = randomPIN;
[Code] ....
that lest method is a bit of a mess i know, i was going to store the log in attempts in a array but thats probly not a good tactic, and that inner for loop is probly unnecessary ?
I have two different Class object arrays storing 3 elements (2 Store arrays, both initialised to hold 3 Product objects). The problem is, I can set data to one array with no problem but my program doesn't want to set the data for my second array.
For instance, The main problem is this method:
public void addData(String store, String newName, int newDemand, double newSetup, double newUnit, double newInventory, double newPrice) //Method that sets the data value for a product { if (store.equalsIgnoreCase("callaghan"))//!!!!Goes from this line in the debugger if (noOfProductsCallaghan==0) { setData(product[0], newName, newDemand, newSetup, newUnit, newInventory, newPrice); noOfProductsCallaghan++; } else if (noOfProductsCallaghan==1)
I am trying to get the program to ask the user to enter the project grade and if it is less than 65, then I want the program to display "fail" or if it is greater than 64 than I want it to display "passed". In this project I have to include a method and I am trying to call it in my if-else statement. I keep getting an error message saying "Project.java:143: error: incompatible types: void cannot be converted to int". I posted my code below. It's a long program, but this part is toward the bottom.
import java.util.Scanner; public class Project { public static void main(String[] args) { //call method welcomeMessage();
/** * This method displays all winner names for a given year. * @param year is the integer parameter asked of the user. */ public void displayAllWinnersForYear (int year) { if (year >= 1993 || year <= 2009) { String[] winnersForTheYear = nobelPrizeWinners.get(year); for (int i = 0; i < winnersForTheYear.length; i++) {
[Code] ....
When year is outside the 1993-2009 range, I get a NullPointerException from line 10. Shouldn't it be skipped entirely since the conditions of its parent IF statement (line 7) is not met?
I am having trouble doing a simple exercise changing a for loop to a while statement, it works fine in the for loop but in the while statement it just prints out 10(it is supposed to count to 0 and print liftoff).
public void run() { int i = 10; while (i>=1) { println(+i+"..."); i--; } println("liftoff..."); }
It has been about 2 years that I'm programming in JAVA and never has this occurred to me about the reason why this happens. So, in this code snippet
public class Test { public static void main(String[] args) { char m = 'A'; int p = 15; System.out.println(m+p); System.out.println("Answer :"+m+p); } }
The statement "System.out.println(m+p);" returns "80" which is evident that the type of the entire expression is promoted to the value of the largest data type int. But in the statement " System.out.println("Answer :"+m+p);, why does the output change to "Answer :A15" but not "Answer :80"?
Implement a Las Vegas slot machine! The machine works as follows. First, it generates three random integers (use import java.lang.Math.*; then call Math.random()*7 to generate a random number between [a,b)) that are in the range of 0-7. Once the numbers are generated, the following rules are used to determine the prize:
- If all three numbers are equal to 7, you are winning $1,000, - If all three numbers are equal, but not equal to 7, you are winning $500, - If two of the numbers are equal to 7 and the third one is six, you are winning $400, - If two numbers are equal, you are winning $100, - Otherwise you are not winning anything.
And for that I wrote:
import java.lang.Math;
public class Assn1_2150130 { public static void main(String[] args) { // Generate three random signle-digit integar from 0-7. int n1 = (int)(Math.random()*7); int n2 = (int)(Math.random()*7); int n3 = (int)(Math.random()*7);
[code]...
But I just can't figure out a way to print out the "YOU WON NOTHING." independently.If I say that n1!=n2 && n2!=n3 && n3!=n1, and then write another line of println. It gives out the number as well as the "NOTHING".
code=Java import java.util.Random; import java.util.Scanner; public final class Derp { public static int WIN, Tick; public static Scanner Input = new Scanner(System.in);
[code]...
why this boolean statement isn't working correctly. It's not detecting that the WIN and Tick are the same and instead chooses to always run the second statement.
Often times i don't remember which package a specific class (like ArrayList) belongs to. Is there an easy way to find that java.util.* is what i need to import, if i wanted to use the class ArrayList ?
I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.
import java.util.Scanner; public class InventorySystem { public static void main(String [] args) { Scanner input = new Scanner(System.in); int count=0; int inputEntered=0; int numberOfItems=0; double cost=0.00; String item; String description;