why is the method not returning the value and its always returning 0?

Main.java
package com.functions;


import java.util.Scanner;


public class Main {
private static int first;
private static int second;
private static int third;

public Main() {
first = 0;
second = 0;
third = 0;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number one: ");
first = in.nextInt();

System.out.print("Enter number two: ");
second = in.nextInt();

System.out.print("Enter number three: ");
third = in.nextInt();

MaxandMin test = new MaxandMin();
test.getFirst();
test.getSecond();
test.getThird();
System.out.println(test.findMax());
System.out.println(test.findMin());
}
}
package com.functions;


import java.util.Scanner;


public class Main {
private static int first;
private static int second;
private static int third;

public Main() {
first = 0;
second = 0;
third = 0;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number one: ");
first = in.nextInt();

System.out.print("Enter number two: ");
second = in.nextInt();

System.out.print("Enter number three: ");
third = in.nextInt();

MaxandMin test = new MaxandMin();
test.getFirst();
test.getSecond();
test.getThird();
System.out.println(test.findMax());
System.out.println(test.findMin());
}
}
MaxandMin.java
package com.functions;

public class MaxandMin {
private int first;
private int second;
private int third;

public MaxandMin() {
first = 0;
second = 0;
third = 0;
}

public int getFirst() {
first = 0;
return first;
}

public int getSecond() {
second = 0;
return second;
}

public int getThird() {
third = 0;
return third;
}

public int findMax() {
int max = first;

if(second > max) {
max = second;
} else if(third > max) {
max = third;
}
return max;
}

public int findMin() {
int min = first;

if(min < second) {
min = second;
} else if (min < third) {
min = third;
}
return min;
}
}
package com.functions;

public class MaxandMin {
private int first;
private int second;
private int third;

public MaxandMin() {
first = 0;
second = 0;
third = 0;
}

public int getFirst() {
first = 0;
return first;
}

public int getSecond() {
second = 0;
return second;
}

public int getThird() {
third = 0;
return third;
}

public int findMax() {
int max = first;

if(second > max) {
max = second;
} else if(third > max) {
max = third;
}
return max;
}

public int findMin() {
int min = first;

if(min < second) {
min = second;
} else if (min < third) {
min = third;
}
return min;
}
}
3 Replies
JavaBot
JavaBot5w ago
This post has been reserved for your question.
Hey @aviliocorteo! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st5w ago
you are litterally setting the variables to 0 in your getters in getFirst, you are doing first=0; and similar in the others also in your findMin and findMax, I think it shouldn't be else if but just two if s after each other
JavaBot
JavaBot5w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?