[Solved] Error: else without if. What went wrong? [closed]

You should do it with a switch : public static void main(String args[]) { System.out.println(“Enter 1 to Add, 2 to Subtract, 3 to Divide, or 4 to Multiply”); int x = keyboard.nextInt(); switch(x){ case 1: System.out.println(“Enter an integer”); int num1 = keyboard.nextInt(); System.out.println(“Enter another integer”); int num2 = keyboard.nextInt(); System.out.println(“The sum of the numbers equals … Read more

[Solved] Creating a small page that generates 3 random words from 3 seperate lists at the click of a button

<html> <body> <script> Array.prototype.randomElement = function () { return this[Math.floor(Math.random() * this.length)] } var list1 = [ “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]; var list2 = [ “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”]; var list3 = [ “car”, “horse”, “gym”, “fair”, “boat”]; function myFunction() { document.getElementById(“demo”).innerHTML = list1.randomElement() + … Read more

[Solved] Positive and negative number values [duplicate]

One way would be to just add a negative sign in front of the value: int myInt = -myInt; Another way to switch between a positive or negative number in a statement would be to multiply it by -1. myInt = myInt * -1; 0 solved Positive and negative number values [duplicate]

[Solved] Find the longest string

We can do this in two lines of code: List<String> list = Arrays.asList(letterlist); String longest = Arrays.stream(letterlist).max(Comparator.comparingInt(String::length)).get(); Demo Inspired by this Code Review question: https://codereview.stackexchange.com/questions/75807/finding-the-longest-string-and-its-length-using-java-streams 0 solved Find the longest string

[Solved] My Java code is not running [closed]

As others stated before, value of remainder is set only once. However, you check it a hundred times expecting it to tell you something else every time. I’d suggest putting it inside a loop, so you get a “fresh” value for every number. public class Even { public static void main(String args[]) { int number … Read more

[Solved] Object Oriented Programming vs. Procedural Programming [closed]

Java is designed to be fully object-oriented while C is a procedural language. I suggest looking at http://www.tutorialspoint.com/cprogramming/c_overview.htm to read about C. Java is not meant to be used for procedural. This is all I can do to help. You need to do some research on the programming paradigms. Practical Explanation : Can anyone Explain … Read more

[Solved] cant add ImageView in a subclass [closed]

Since you don’t have a code posted, I have to guess. Instead of using this keyword, try to use MainActivity.this. If you have a subclass in your activity, you will most likely use the context of the running activity. 1 solved cant add ImageView in a subclass [closed]

[Solved] How to get mongoDB aggregated month wise data using java [closed]

Use the aggregation framework with following aggregation pipeline (Mongo shell implementation): db.ledger.aggregate([ { “$unwind”: “$Accounts” }, { “$project”: { “Total_Credits” : “$Accounts.Total_Credits”, “Total_Debits” : “$Accounts.Total_Debits”, “month_year” : { “$substr”: [ “$Accounts.Date”, 3, -1 ] } } }, { “$group”: { “_id”: “$month_year”, “Total_Credits”: { “$sum”: “$Total_Credits” }, “Total_Debits”: { “$sum”: “$Total_Debits” } } } ]) … Read more

[Solved] How to represent distinct query of mongo db in java language [closed]

Considering item.sku is of a String Type, you can fire your distinct query like this: BasicDBObject filter = new BasicDBObject(); filter.put( “dept”, “A” ); MongoCursor<String> c = db.getCollection(“inventory”).distinct(“item.sku”, filter, String.class).iterator(); Hope this helps. solved How to represent distinct query of mongo db in java language [closed]

[Solved] Java user control desktop application [closed]

You can solve this problem in the following steps: 1- Search the internet about .DLL files for locking and unlocking your windows Desktop. 2- .DLL files are written in C or C++ language. 3- You can invoke the .DLL file if and only if the java method from where you’re invoking is declared as native(Also … Read more