Search the Community
Showing results for tags 'if'.
-
-
I'm working with an ArrayList and i'm trying to use the isEmpty lmethod, but for some reason the else clause is highlighted as an error and I really have no clue why. Here is the entire program: package main; //need to import ArrayList from within java.util package import java.util.ArrayList; public class IntegerArrayListDemo { public static void main(String[] args) { //create an ArrayList of numbers using the Integer wrapper class ArrayList<Integer> list = new ArrayList<Integer>(); //print list, should be empty System.out.println(list.toString()); //populate with some numbers list.add(8); //auto-boxing, actually: add(new Integer(8)) list.add(32); list.add(5); //using the other add method list.add(1,5); //inserts 5 at index 1 list.add(0,104); //inserts 104 at index 0 //print list contents System.out.println(list.toString()); //output the current size of the list System.out.println("The size is: " + list.size()); //print element at index 0 using get method System.out.println("First element is: " + list.get(0)); //searches for item (5) and returns index int pos = list.indexOf(5); System.out.println("Index of 5: (expected 2) result is " + pos); //use contains() to check whether some number is in the list if (list.contains(104)) { System.out.println("The list contains 104"); //should print this } else { System.out.println("The list does NOT contains 104"); } //print using a for-i loop with size() and get(i) System.out.println("\nUsing standard for-i loop"); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } //print using for-each loop System.out.println("Using for-each loop"); for (Integer x : list) { System.out.println(x); } //print using forEach method (added in Java 8) System.out.println("Using forEach method"); //passes a lambda expression to the method list.forEach(x -> System.out.println(x)); //TEST OTHER METHODS HERE... list.remove(3); //removes element an index 3 System.out.println(list.toString()); list.set(2, 14); //changes index 2 from element 5 to 14 System.out.println(list.toString()); list.clear(); //clears all elements from the list System.out.println(list.toString()); if (list.isEmpty()); System.out.println(list + " " + "Is empty"); else //My IDE is saying this is an error System.out.println(list + " " + "Is not empty"); } } The bit your looking for is the if else statmement right at the bottom of the program.
- 3 replies
-
- arraylists
- java
-
(and 4 more)
Tagged with:
-
Hey everyone, how are you guys today? I'm doing a round robin scheduler and i've come across this problem. The tempodeExecucao variable is in the correct amount and so does the cpu[0].vetordeIO as the screenshot shows. but it won't go into the if. i need the verification to work so i can send the process on the queue. thanks for the help! if (cpu[0].vetorDeIO.length != 0) { if (cpu[0].tempodeExecucao == cpu[0].vetorDeIO) { System.out.println("OPERACAO IO"); System.out.println("NOME E TEMPO DE EXECUCAO " + cpu[0].getNome() + cpu[0].tempodeExecucao); filaexecucao.enqueueProcess(cpu[0]); cpu[0] = filaexecucao.dequeueProcess(); break; } }
- 4 replies
-
- java
- programming
-
(and 3 more)
Tagged with:
-
I am creating a bash script that installs programs and themes on Ubuntu Linux. Currently my script goes a little something like this: GIMP=$" " gimp "Known as GIMP, GNU Image Manipulation Program is a free and open source photo editor." \ if [[ $GIMP == "gimp" ]] then sudo apt-get install $GIMP else echo "did not install gimp" fi I am using ZENITY, which lets me open a text dialog box with columns, rows and check boxes. The first part is my variable, where sets the variable GIMP as nothing or as "gimp". I have tested this and have confirmed that when I select the checkbox next to "gimp" it changes the value of the variable to "gimp" The problem is that the if then statement is not working at all in the way it should, it always echos "did not install gimp".
-
Hi all, sorry to bother you all for such a stupid, queston/request. I just learned that my girlfriend was pregnant (Hourray, congrats etc ...) but it was a huge surprise on our side, so nothing is ready Since I am an « old/still there » hard gamer and pc builder, my question is if any other t-shirts/polo are available - other then the ones onlines ? I am living in Luxembourg (yeah it is a country - middle of Germany, France and belgium) so the sending fee are of 50$, so I wanted to know if something more « personnel » would be possible if payed for ? (Love the behind of Linus office, pictures/3D of pc material) Sorry for all the mistakes, and if this question doesn’t belong here, didn’t saw any other place to ask this ? good day
-
I searched in other forums (7 different forums) and websites (a lot of them, included office.com, etc) and a lot of other websites, BUT: I still have the problem with this funcion: =if(A1='D'; 3; 0) It shows me everytime a error: Excel says me to edit it to: '=if...' But this is dumb. My solutions, which i tried: ''D'' D (with space) ´D´ --> Not working, Excel still dumb. Help?!???
- 7 replies
-
- excel
- if-function
-
(and 4 more)
Tagged with:
-
I am attempting to write a nested if statement in JavaScript and it is not working. I am not sure what I am doing wrong and would like some assistance. The if statements are long and will only get longer. I choose to use if statements simply because I do not know how to create a VLOOKUP type function in JS. I have researched a way to accomplish this and found various codes, the problem is I do not understand them thus I cannot edit them to fit my needs. Any help will be greatly appreciated! /* The following vars are used to get the proposed kWh */ var apropkWh1; var apropkWh2; var apropkWh3; var apropkWh4; var apropkWh5; /* The following vars are used to get the proposed kWh */ var propkWh1 = if (document.getElementById("RbR5.1").value = document.getElementById("RN1.1").value) {apropkWh1 = document.getElementById("RN5.1").value * document.getElementById("burnHrs1").value;} else if (document.getElementById("RbR5.1").value = document.getElementById("RN1.2").value) {apropkWh1 = document.getElementById("RN5.2").value * document.getElementById("burnHrs1").value;} else if (document.getElementById("RbR5.1").value = document.getElementById("RN1.3").value) {apropkWh1 = document.getElementById("RN5.3").value * document.getElementById("burnHrs1").value;} else if (document.getElementById("RbR5.1").value = document.getElementById("RN1.4").value) {apropkWh1 = document.getElementById("RN5.4").value * document.getElementById("burnHrs1").value;} else if (document.getElementById("RbR5.1").value = document.getElementById("RN1.5").value) {apropkWh1 = document.getElementById("RN5.5").value * document.getElementById("burnHrs1").value;} var propkWh2 = if (document.getElementById("RbR5.2").value = document.getElementById("RN1.1").value) {apropkWh2 = document.getElementById("RN5.1").value * document.getElementById("burnHrs2").value;} else if (document.getElementById("RbR5.2").value = document.getElementById("RN1.2").value) {apropkWh2 = document.getElementById("RN5.2").value * document.getElementById("burnHrs2").value;} else if (document.getElementById("RbR5.2").value = document.getElementById("RN1.3").value) {apropkWh2 = document.getElementById("RN5.3").value * document.getElementById("burnHrs2").value;} else if (document.getElementById("RbR5.2").value = document.getElementById("RN1.4").value) {apropkWh2 = document.getElementById("RN5.4").value * document.getElementById("burnHrs2").value;} else if (document.getElementById("RbR5.2").value = document.getElementById("RN1.5").value) {apropkWh2 = document.getElementById("RN5.5").value * document.getElementById("burnHrs2").value;} var propkWh3 = if (document.getElementById("RbR5.3").value = document.getElementById("RN1.1").value) {apropkWh3 = document.getElementById("RN5.1").value * document.getElementById("burnHrs3").value;} else if (document.getElementById("RbR5.3").value = document.getElementById("RN1.2").value) {apropkWh3 = document.getElementById("RN5.2").value * document.getElementById("burnHrs3").value;} else if (document.getElementById("RbR5.3").value = document.getElementById("RN1.3").value) {apropkWh3 = document.getElementById("RN5.3").value * document.getElementById("burnHrs3").value;} else if (document.getElementById("RbR5.3").value = document.getElementById("RN1.4").value) {apropkWh3 = document.getElementById("RN5.4").value * document.getElementById("burnHrs3").value;} else if (document.getElementById("RbR5.3").value = document.getElementById("RN1.5").value) {apropkWh3 = document.getElementById("RN5.5").value * document.getElementById("burnHrs3").value;} var propkWh4 = if (document.getElementById("RbR5.4").value = document.getElementById("RN1.1").value) {apropkWh4 = document.getElementById("RN5.1").value * document.getElementById("burnHrs4").value;} else if (document.getElementById("RbR5.4").value = document.getElementById("RN1.2").value) {apropkWh4 = document.getElementById("RN5.2").value * document.getElementById("burnHrs4").value;} else if (document.getElementById("RbR5.4").value = document.getElementById("RN1.3").value) {apropkWh4 = document.getElementById("RN5.3").value * document.getElementById("burnHrs4").value;} else if (document.getElementById("RbR5.4").value = document.getElementById("RN1.4").value) {apropkWh4 = document.getElementById("RN5.4").value * document.getElementById("burnHrs4").value;} else if (document.getElementById("RbR5.4").value = document.getElementById("RN1.5").value) {apropkWh4 = document.getElementById("RN5.5").value * document.getElementById("burnHrs4").value;} var propkWh5 = if (document.getElementById("RbR5.5").value = document.getElementById("RN1.1").value) {apropkWh5 = document.getElementById("RN5.1").value * document.getElementById("burnHrs5").value;} else if (document.getElementById("RbR5.5").value = document.getElementById("RN1.2").value) {apropkWh5 = document.getElementById("RN5.2").value * document.getElementById("burnHrs5").value;} else if (document.getElementById("RbR5.5").value = document.getElementById("RN1.3").value) {apropkWh5 = document.getElementById("RN5.3").value * document.getElementById("burnHrs5").value;} else if (document.getElementById("RbR5.5").value = document.getElementById("RN1.4").value) {apropkWh5 = document.getElementById("RN5.4").value * document.getElementById("burnHrs5").value;} else if (document.getElementById("RbR5.5").value = document.getElementById("RN1.5").value) {apropkWh5 = document.getElementById("RN5.5").value * document.getElementById("burnHrs5").value;}
- 9 replies
-
- javascript
- nested if
- (and 4 more)
-
<html> <head> <title>Eksempel_2</title> <meta charset="utf-8" /> <script> function btnUtfor_onclick_tekst() { document.getElementById("pMelding").innerHTML = "DerpDerp"; document.getElementById("btnUtfor").onclick = "btnUtfor_onclick_blank()"; } function btnUtfor_onclick_blank() { document.getElementById("pMelding").innerHTML = "..."; document.getElementById("btnUtfor").onclick = "btnUtfor_onclick_tekst()"; } </script> </head> <body> <input id="btnUtfor" type="button" value="Trykk meg" onclick="btnUtfor_onclick_tekst()" /> <p id="pMelding"></p> </body> </html> can someone please explain why this doesn't work and how to fix it, I'm very (very) new to javascript and coding in general
- 15 replies
-
- javascript
- coding
-
(and 3 more)
Tagged with:
-
So I'm writing my final for Visual Basic and I've come across some code which if triggered I need to leave the "If" it is in and start the sub back at the beginning. How would one go about this? I dont want to close out of the sub with exit sub but just go back to the beginning of it without resetting it or anything.
- 1 reply
-
- visual basic
- if
-
(and 2 more)
Tagged with:
-
title says it all basicly, i want to set up an if statement that knows if im on T or CT and another one that knows if i have the bomb or not, pritty sure you cant use if statements in the console but if there is a way that someone knows of thats not just having 2 keys that swap the binds i want when i press them. also all this is because i have custom binds to my mouse i.e mouse4 gets out my primary and mouse5 my knife and if i have the bomb mouse3 gets out the bomb(relly usefull), the reson i want this is that as ct or if i dont have the bomb i want mouse3 to get out my primary, might just re-do all of my binds if you cant have if statements but if you can i want to know. thanks for any replies and help
-
*NOTE: i'm just starting out, so if i made some really stupid mistakes, don't bash me with them. I am creating a program where you have to insert the right password else it gives you one less try and you can try again. If you fail 3 times it locks. I already made something similar but i had the problem where it also didn't recognize the correct password. After i deleted it and quit, tried again and now i wrote this from scratch and a lot more things don't work as they should. PROBLEMS 1. How to make the while loop take the input(password in this case) and compare it to the correctPass. I just wrote 1 != 2 so it loops until it executes "else" and then breaks out of the loop, but it doesn't work. 2. Also the "attempt" subtraction part also doesn't work. 3. If i enter the correct password it still gives me the "Try again" Heres the code importjava.util.Scanner; public class Application {public static void main(String[] args) { while(1 != 2) { String correctPass = "Java"; System.out.println("Enter the password"); Scanner input = new Scanner(System.in);String line = input.nextLine(); if(line == correctPass) {System.out.println("Wellcome back sir!");break;}else {intnum = 3;System.out.println("Wrong password, please try again! " + num + " attempts left!");num = num - 1;if(num == 0) {System.out.println("System Locked!");break;}} }}}
-
So I am looking for a really quiet PSU for <$80. I have the option to get an EVGA Supernova GS with fanless option if the system is not under load, 80+ gold and fully modular, or a Be Quiet! Pure Power L8 non-modular 80+ bronze PSU. Is it worth getting the Be Quiet! PSU? My case won't have a clear side panel and i can just tuck unused cables since I have a fairly big case.
-
I am going 2 mount 2 120mm fans on the top of a Bitfenix Prodigy M so should I use the S12A or F12 fans? Because there is going to be the graphics card right against the top of the case.
-
I'm trying to answer this question: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. I made this program to solve the problem: #include <stdio.h>int main (void){ int fib1, fib2, fib3; fib1 = 1; fib2 = 2; int sum = 0; while (fib3 < 4000000) { fib3 = fib1 +fib2; fib1 = fib2; fib2 = fib3; if (fib3 % 2 == 0) sum += fib3; } printf("%i\n", sum);} The problem is that it just prints 0 every time. It doesn't even run through the if statement, and if i put a printf in the while loop it doesn't execute it. What is my problem?
-
Hello ladies and gents, this is my first post in here so... Hugs and kisses from central Europe About my issue: Im planning to upgrade my gpu from R9 270x windforce to either sapphire r9 290 tri x (mainly aiming at this one as I can purchase it with a real-deal bargain) or zotac gtx 970 non reference (not alpha or any oc edition stuff, just the normal gtx 970 non reference design ). And as it was all to easy about choosing the gpu within the range of my wallet, I started to tremble when it came to power consumption. Specs of the system im currently using are as follows: FX-8350 oc'd to 4.6 ghz with some fancy thermalright true spirit cooling Asus m5a97 evo r2.0 2x4gb ddr3 hyperx blu 1600mhz crucial m500 240gb standard lg dvd drive and finally, the psu (and by God, I know its outdated, I bought it a year ago, brand new, spent 40 euros on it- it was like almost stealing it- ocz modxstream pro 700w, 80 plus. Now. I get the point that this particular psu has two 12v rails, each of them with 25a on them, 1six pin pcie, 1x8 pin pcie connectors included. Am I going to have any issues with running considerated gpus, especially r9 290? I don't know what to pick now, and I became totally confused with the whole railing stuff this upgrade took into account. Please, be merciful. Also, I thank for every helping hand in advance.
-
Okay guys, if you had one song you HAD to listen to for the rest of your life what one would you choose? my choice
-
Ask away :)
-
Cooler Master CM Force 500 Midi Tower Corsair RM450, 450W PSU ATX 12V V2.4, 80 Plus Gold, Modular, 2x 6+2-pin PCIe, 6x SATA, 4x Molex, 1x FD Crucial DDR3 BallistiX Sport 1600MHz 8GB 8GB kit(4GBx2), CL9, 1.5V, CL9-9-9-24 Gigabyte GA-H81M-S2PV, Socket-1150 m-ATX, H81, DDR3, 1xPCIe-x16, USB3.0, VGA, DVI, COM-port, Haswell Gigabyte GeForce GTX 750Ti 2GB PhysX "Windforce 2X OC", with F2P coupon : Heroes of Newerth, Path of Exile, Warface Intel Pentium G3430 Socket-LGA1150, Dual Core, 3.3GHz, 3MB, 54W, HD Graphics, Boxed w/fan, Haswell Microsoft Windows 7 Home Premium NO OEM, 64bit, SP1 Samsung DVD Writer, SH-224DB SATA, DVD±R: 24x, DVD±R DL: 8x, CD-R: 48x, Retail, Ivory/Black/Silver Seagate Barracuda® 1TB SATA 6Gb/s (SATA 3.0), 64MB Cache, 7200RPM, 3.5" what kind of performance will i get from this and should i change anything?
-
I don't completely understand how a NAS works, my understanding is that NAS sends the files to the router and then the router send it to the device but i'm not sure if my connection to the internet effects the speed. My connection to the router is fast but here in Australia my connection the the internet isn't that great (i get about 800kbps down on steam) And how much do slow drives affect the speeds?
-
If you look at the temps of their air coolers, and how they stomp on the competition like they're nothing. Imagine for a moment what would happen. I foresee the universe ending.
- 16 replies
-
- watercooler
- noctua
- (and 8 more)
-
Hi guys, Firstly, here is the code: IF "%Input%"=="1" goto :skip1[code to run for 1]:skip1IF "%Input%"=="2" goto :skip2[code to run for 2]:skip2 So... Basically, that code takes input from a user from earlier in the Batch file, sets it as the Input variable, then uses that input to run either code for 1 or code for 2. It's like this: "If you want these printers, press 1. If you want these other printers, press 2." However, it installs all the printers. It doesn't skip to :skip1 or :skip2. <-- The Problem. What am I getting wrong? Does the If function have an error in it? That is exactly as it is written in the batch file. Or am I misusing the goto function? Any help is appreciated. I've already tried googling, and this is basically copy/pasted from a post on StackOverflow.com which was voted and chosen as correct for this very use. So I'm confused to be honest. Thanks, Vitalius.
-
Hi guys, ... Ok, so [Title], would it noticeably affect performance? Has anyone tried sandwiching something more conductive between a back plate and the GPU? If so, does it make a noticeable difference? I'd imagine it would, unless the backplates are good enough on their own, such that it wouldn't be a noticeable difference. Thoughts on this idea? Are there better alternatives? Is it cost effective? Etc etc?