Jump to content

Why doesn't my code work properly?

creativename
Go to solution Solved by madknight3,

You missed a combination. You have Math.max(hana, dul) twice where one of them should be comparing hana and set.

 

int mid = Math.min(Math.min(Math.max(hana,dul), Math.max(dul,set)),Math.max(hana,dul));

The objective of my code is to create a method that finds the mid of 3 numbers that the user inputs.

my code is

 

import java.util.Scanner;class mid{    public static void main(String args[])    {        Scanner kb1 = new Scanner(System.in);        Scanner kb2 = new Scanner(System.in);        Scanner kb3 = new Scanner(System.in);        int ichi;        int ni;        int san;                   System.out.print("Input first number: ");           ichi = kb1.nextInt();           System.out.print("\nInput second number: ");           ni = kb2.nextInt();           System.out.print("\nInput third number: ");           san = kb3.nextInt();         System.out.println("");         System.out.println("");                         System.out.print(ichi + " ");               System.out.print(ni + " ");               System.out.print(san + " ");                 System.out.println("");                 int kotae = findMid(ichi, ni, san);               System.out.println("");                 System.out.println("The mid is " + kotae +".");   }        public static int findMid(int hana, int dul, int set)      {           int mid = Math.min(Math.min(Math.max(hana,dul), Math.max(dul,set)),Math.max(hana,dul));           return mid;       }}
 

 

 

 

It seems to work for single digit numbers, but as soon as i plug in double digit or triple digit numbers it doesn't work properly. It seems to only look at the ones place.

Edited by alpenwasser
code tags :)

CPU: Intel Core i7 2600k | Mootherboard: ASUS P8z68v-Pro | GPU: EVGA GTX780Ti 3GB | RAM: Kingston HyperX Genesis 8GB (4GBx2) 1600mhz | PSU: Corsair AX760 | STORAGE: Samsung 840 Pro 512GB | COOLER: Noctua NH-C14 | CASE: Fractal Design Define R4 Pearl Black | Operating SystemWindows 7 Professional 64-bit |

Link to comment
Share on other sites

Link to post
Share on other sites

You missed a combination. You have Math.max(hana, dul) twice where one of them should be comparing hana and set.

 

int mid = Math.min(Math.min(Math.max(hana,dul), Math.max(dul,set)),Math.max(hana,dul));

Link to comment
Share on other sites

Link to post
Share on other sites

You missed a combination. You have Math.max(hana, dul) twice where one of them should be comparing hana and set.

int mid = Math.min(Math.min(Math.max(hana,dul), Math.max(dul,set)),Math.max(hana,dul));

Are you serious? I feel so retarded... thank you.

CPU: Intel Core i7 2600k | Mootherboard: ASUS P8z68v-Pro | GPU: EVGA GTX780Ti 3GB | RAM: Kingston HyperX Genesis 8GB (4GBx2) 1600mhz | PSU: Corsair AX760 | STORAGE: Samsung 840 Pro 512GB | COOLER: Noctua NH-C14 | CASE: Fractal Design Define R4 Pearl Black | Operating SystemWindows 7 Professional 64-bit |

Link to comment
Share on other sites

Link to post
Share on other sites

Why are you using Japanese for your variable names and Korean for your parameter names?

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Why are you using Japanese for your variable names and Korean for your parameter names?

Cause im a halfie :U how did u even recognize korean, most people only know il i sam.

CPU: Intel Core i7 2600k | Mootherboard: ASUS P8z68v-Pro | GPU: EVGA GTX780Ti 3GB | RAM: Kingston HyperX Genesis 8GB (4GBx2) 1600mhz | PSU: Corsair AX760 | STORAGE: Samsung 840 Pro 512GB | COOLER: Noctua NH-C14 | CASE: Fractal Design Define R4 Pearl Black | Operating SystemWindows 7 Professional 64-bit |

Link to comment
Share on other sites

Link to post
Share on other sites

Cause im a halfie :U how did u even recognize korean, most people only know il i sam.

 

I recognized it because in my earlier life I used to teach a Korean martial art (Kuk Sool Won). In the upper echelons basic Korean was a requirement.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

I recognized it because in my earlier life I used to teach a Korean martial art (Kuk Sool Won). In the upper echelons basic Korean was a requirement.

Thats cool. I had a pretty hard time picking up korean from my mom because so many letters looked the same eg ㅁ ㅈ ㅅ

CPU: Intel Core i7 2600k | Mootherboard: ASUS P8z68v-Pro | GPU: EVGA GTX780Ti 3GB | RAM: Kingston HyperX Genesis 8GB (4GBx2) 1600mhz | PSU: Corsair AX760 | STORAGE: Samsung 840 Pro 512GB | COOLER: Noctua NH-C14 | CASE: Fractal Design Define R4 Pearl Black | Operating SystemWindows 7 Professional 64-bit |

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×