0

How do i put the input if scanner in the program? (If there is a way.)

Take this code public class Password { public static void main(String[] args) { int I = 12; if(I == 12){ System.out.println("Hello!"); }else{ System.out.println("Nope"); } } } But say I want to put what I make the input in the program(where I want to put it will be surrounded by these[ ] ) public class Password { public static void main(String[] args) { int I = [12]; if(I == 12){ System.out.println("Hello!"); }else{ System.out.println("Nope"); } } } How do I do that?

11th Mar 2017, 2:49 AM
One Puncher
One Puncher - avatar
1 Antwort
0
import java.util.Scanner; public class Password { public static void main(String[] args) { String i; i = "12"; Scanner input = new Scanner (System.in); System.out.println("Input:"); // this is where the user input like 12 String i = input.next(); if(input.equals(i) ){ System.out.println("Hello!"); }else{ System.out.println("Nope"); } } }
11th Mar 2017, 3:00 AM
Malvin Ravela
Malvin Ravela - avatar