+ 1

How to make user input comparasion in Java

import java.util.scanner; public class test{ public static void main(String[]args){ Scanner a = new Scanner(System.in); if(a.int()>1){ System.out.println("hai"); } } } /* https://code.sololearn.com/cpvWvJOScf62/?ref=app this is a simple example, can someone help */

27th Sep 2018, 8:11 AM
David Agustinus
David Agustinus - avatar
2 odpowiedzi
+ 10
Use nextInt() method of Scanner class to read integer input from user. For example: Scanner a = new Scanner(System.in); int n = a.nextInt(); if(n>1){ System.out.println("hai"); }
27th Sep 2018, 8:46 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 2
import java.util.Scanner; public class Program{ public static void main(String[] args) { Scanner a = new Scanner(System.in); int input_0 = a.nextInt(); if(input_0 > 5){ System.out.println("hai"); }else{ System.out.println("no hai"); } } }
27th Sep 2018, 8:48 AM
Ramphy Aquino Nova
Ramphy Aquino Nova - avatar