samedi 28 février 2015

Why does one value keep appearing larger than the other?

So I'm trying to do this small program as a exercise for class and I honestly cannot figure out why the value for x keeps replacing w. Could someone explain to me why this is happening. I know ASCII-wise w has a smaller value than x so i genuinely don't understand.

import java.util.*;



public class SmallestIntMod
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a value for w: ");
int w = scan.nextInt();
int smallest = w;
System.out.println("Enter a value for x: ");
int x = scan.nextInt();
if (x < smallest);
{
smallest = x;
}
System.out.println("Enter a value for y: ");
int y = scan.nextInt();
if (y < smallest)
{
smallest = y;
}
System.out.println("Enter a value for z: ");
int z = scan.nextInt();
if (z < smallest)
{
smallest = z;
}
System.out.println("The smallest value is: " + smallest);
}
}

Aucun commentaire:

Enregistrer un commentaire