Questions tagged [java]

Programming questions are off-topic here. Do not ask questions about how to write code in Java. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

112 questions
2
votes
1 answer

Find path from node

I have a question where I need to find a path from node 1 to node N in an undirected graph given weights in O(A Log^2 A). The total cost of each path must not exceed T amount of total weight. For no1, you cannot use this path because its total cost…
user100701
1
vote
1 answer

Is there a general pattern/structure/format to most (if not all) computer functions?

First time posting. I know this is a very generalized question, sorry for that, I don't know how to more appropriately word this. I've noticed a tread, a pattern in methods, it seems in almost all methods, for example, in Java (haven't programmed…
1
vote
0 answers

Implementing TCP request and answer

I'm creating an application where client connects to server, retrieves some data and after that connection is closed. He spends some time changing that data and then connects again to the server sends it back and connection is closed. At server…
Artūrs
  • 11
  • 2
1
vote
1 answer

Indentations in If-Else?

I am a beginner at Java and this code example came up in class: int horsepower = 15; if(horsepower > 15) if(horsepower <= 20) System.out.println("There is a lot of horsepower"); else System.out.println("The…
1
vote
0 answers

Java configuration for int-amqp

I am trying to convert a XML based configuration to JAVA based configuration. Can someone please let me know the java annotation based configuration for the following
ABCDEFGHI
  • 11
  • 1
0
votes
1 answer

Inheritance problem (JAVA)

Here I have created 2 classes , $A$ is the super class of $B$ , i.e , $B$ inherits the features of class $A$. Now I don't know exactly what statement (1) does but I am speculating as follows ,kindly correct me if I am wrong , An object of $B$ is…
User9523
  • 111
  • 5
0
votes
1 answer

Why is this control flow graph correct?

Given the following method written in Java: private void collatz(List values) { int size = values.size(); if (size == 0 || values.get(size=1) <= 1) { return; } else { int last =…
Monika
  • 183
  • 1
  • 10
0
votes
1 answer

Creating sum of all numbers within a sequence

Write an algorithm that, given sequence seq of n numbers where 3 <= n <= 1000 and each number k in seq 1 <= k <= 200, finds maximum sum by repeatedly removing one number from seq, except for first and last number in seq, and adding its value to sum…
Shyver
  • 31
  • 4
0
votes
1 answer

What is a constructor in java?

I have checked many websites but did not get the right answer. what is the meaning of constructor in java?
Ujala Ijaz
  • 11
  • 3
0
votes
1 answer

Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2

Given (n) , what is the Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2. Is there any way I can re-write this code just without using nested loop? int counter=0; int x=0; for (int i =(int) n-1; i>=0 ; i--){ if(i ==…
Victoria
  • 1
  • 1
0
votes
1 answer

Why whenever a caller or client modifies a library collection class, all iterators are made invalid?

Whenever a caller or client modifies a library collection class, all iterators are made invalid (with the exception of the iterator through which the change was made, in the case of remove). Give a reason for this rule in the case of an array list…
Java77
  • 1
  • 1
-1
votes
1 answer

Beginner question in Java

I am just starting to study Java and was wondering why the following code if(x>2) x*=2; if(x>4)x=0; System.out.println(x); returns 0 for any value of x greater than 2. For example, when x=3, why would 6 not be returned?
SifatR
  • 109
  • 2
-1
votes
1 answer

Why does this statement evaluate to 176?

int y = 10; int z; z = (++y * (y++ + 5)); // Evaluates to 176 According to me this should evaluate to 180. Please provide an explanation as well which relates to precedence and associativity.
-1
votes
1 answer

Methods in Java with/without return? Simple but new to coding

I want to make this program below but I'm not sure how i would start them. Would i use methods with or without return? I have this due tomorrow and cannot figure it out. I've wrote the code multiple times but ended up deleteing it all. Part 1: …
JayD
  • 1
-1
votes
1 answer

"Cannot return a value from a method with void result type" but it's not void?

In Java, I'm getting the error for all my return statements that I can't return a value with a void result type, but I don't declare the return type as void anywhere, and I'm really not sure what the issue is. Here's my code: public class Card…
eap
  • 1
1
2