Eva Meglič Eva Meglič - 8 months ago 42
Java Question

I don't know how to fix this

I have this assignment I have to do.. and I don't know how to fix the problem so that my program will work.

import java.util.Scanner;
public class Work6{

public static void main (String[] args){
String x;
String y;
Scanner in = new Scanner(System.in);
System.out.println("Number 1: ");
x = in.nextLine();
System.out.println("Number 2: ");
y = in.nextLine();

if (x > y){
System.out.println("Bigger number: " + x);

else if (y > x){
System.out.println("Bigger number: " + y);


Basically I have to write a program that asks for two numbers and then tells me which one is bigger. Can you just please tell me what am I doing wrong?

Thanks, Eva

Answer Source

Just use in.nextInt() instead of in.nextLine(). It will return an int instead of a string!