Skip to content
Advertisement

Tag: if-statement

How do I refactor multiple if-else statements in Java?

How do I refactor all this code that seems repetitive and too long, is there a way to make it shorter? I have tried using the Switch statement but that does not work in this circumstance. the “typeOfData” variable holds a String that is used to match relevant lines. Answer Simplify You can extract the common lines, before or after

Skipping To The Next if Statement from Inside a for Loop

I’ve been learning some Java in my spare time and I’m a beginner, so I’m very sorry if I don’t understand some simple concepts. I’ve been trying to make a “Robot” move around an already made map. I’ve been trying to make lines of a text file into multiple arrays (ie. moving forward, turning left, turning right). Then, I’ve been

how to properly check if a string is in txt file

I’m writing a program that manages a library. This part of the program is where you borrow a book, but only if it’s in the library, so I check if the book is in the library but it always comes back negative even if the string is in the library txt file. What should I do? Answer You are just

Ordered or unordered Sequence problem in java

I am facing problem in solving the question below:- (can someone please help????) Write a program that reads a sequence of integer numbers and outputs true if the sequence is ordered (in ascending or descending order), otherwise, false. Keep in mind, if a number has the same value as the following number, it does not break the order. The sequence

Advertisement