0

How to use user input value with the Conditionals and Loops Logical Statements

import java.util.Scanner; public class soloiest{ //I tried something like this it shows erroe public static void main(String[] args){ Scanner age = new Scanner(System.in); System.out.println(age.nextInt()); Scanner salary = new Scanner(System.in); System.out.println(salary.nextInt()); if (age > 18 && salary > 1000){ System.out.println("You should invest"); }else { System.out.println("Next time"); } } }

2nd Jun 2020, 6:04 AM
Ullas Kunder
Ullas Kunder - avatar
3 odpowiedzi
+ 2
You first create a Scanner object then using that reference you take input values. Scanner sc = new Scanner(System.in); int age = sc.nextInt(); int salary = sc.nextInt(); Your condition goes here.
2nd Jun 2020, 6:30 AM
Avinesh
Avinesh - avatar
+ 2
U mean that or what u need ? i will help u put using python while true: A = input("pls enter your age : ") S= input(" pls enter your salary : ") if A >18 and S>1000: print(" You should invest") else: print("Next time") except: print(" error") print("finish") break -------------------------------------------------- this program continue receive 2 inputs from user till user input wrong values in case if error in type of age or salary as the type of age and salary should be integer
2nd Jun 2020, 6:22 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
0
Thanks Avinesh
2nd Jun 2020, 7:03 AM
Ullas Kunder
Ullas Kunder - avatar