Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 KB | None | 0 0
  1. System.out.println("Enter your username: ");
  2. Scanner = input(); // Or something like this, I don't know the code
  3.  
  4. Scanner sc = new Scanner(System.in);
  5. int i = sc.nextInt();
  6.  
  7. System.out.println("Enter your username: ");
  8. Scanner scanner = new Scanner(System.in);
  9. String username = scanner.nextLine();
  10. System.out.println("Your username is " + username);
  11.  
  12. Scanner scan = new Scanner(System.in);
  13. String myLine = scan.nextLine();
  14.  
  15. String name = null;
  16. int number;
  17.  
  18. java.io.BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  19. name = in.readLine(); // If the user has not entered anything, assume the default value.
  20. number = Integer.parseInt(in.readLine()); // It reads only String,and we need to parse it.
  21. System.out.println("Name " + name + "t number " + number);
  22.  
  23. java.util.Scanner sc = new Scanner(System.in).useDelimiter("\s");
  24. name = sc.next(); // It will not leave until the user enters data.
  25. number = sc.nextInt(); // We can read specific data.
  26. System.out.println("Name " + name + "t number " + number);
  27.  
  28. // The Console class is not working in the IDE as expected.
  29. java.io.Console cnsl = System.console();
  30. if (cnsl != null) {
  31. // Read a line from the user input. The cursor blinks after the specified input.
  32. name = cnsl.readLine("Name: ");
  33. System.out.println("Name entered: " + name);
  34. }
  35.  
  36. Reader Input: Output:
  37. Yash 777 Line1 = Yash 777
  38. 7 Line1 = 7
  39.  
  40. Scanner Input: Output:
  41. Yash 777 token1 = Yash
  42. token2 = 777
  43.  
  44. System.out.print("Insert a number: ");
  45. int number = input.nextInt();
  46. input.nextLine(); // This line you have to add (it consumes the n character)
  47. System.out.print("Text1: ");
  48. String text1 = input.nextLine();
  49. System.out.print("Text2: ");
  50. String text2 = input.nextLine();
  51.  
  52. in.nextInt(); // It just reads the numbers
  53.  
  54. in.nextLine(); // It get the String which user enters
  55.  
  56. import java.util.Scanner;
  57.  
  58. class GetInputFromUser {
  59. public static void main(String args[]) {
  60. int a;
  61. float b;
  62. String s;
  63.  
  64. Scanner in = new Scanner(System.in);
  65. System.out.println("Enter a string");
  66. s = in.nextLine();
  67. System.out.println("You entered string " + s);
  68.  
  69. System.out.println("Enter an integer");
  70. a = in.nextInt();
  71. System.out.println("You entered integer " + a);
  72.  
  73. System.out.println("Enter a float");
  74. b = in.nextFloat();
  75. System.out.println("You entered float " + b);
  76. }
  77. }
  78.  
  79. import java.util.Scanner;
  80.  
  81. public class ScannerDemo {
  82. public static void main(String[] arguments){
  83. Scanner input = new Scanner(System.in);
  84.  
  85. String username;
  86. double age;
  87. String gender;
  88. String marital_status;
  89. int telephone_number;
  90.  
  91. // Allows a person to enter his/her name
  92. Scanner one = new Scanner(System.in);
  93. System.out.println("Enter Name:" );
  94. username = one.next();
  95. System.out.println("Name accepted " + username);
  96.  
  97. // Allows a person to enter his/her age
  98. Scanner two = new Scanner(System.in);
  99. System.out.println("Enter Age:" );
  100. age = two.nextDouble();
  101. System.out.println("Age accepted " + age);
  102.  
  103. // Allows a person to enter his/her gender
  104. Scanner three = new Scanner(System.in);
  105. System.out.println("Enter Gender:" );
  106. gender = three.next();
  107. System.out.println("Gender accepted " + gender);
  108.  
  109. // Allows a person to enter his/her marital status
  110. Scanner four = new Scanner(System.in);
  111. System.out.println("Enter Marital status:" );
  112. marital_status = four.next();
  113. System.out.println("Marital status accepted " + marital_status);
  114.  
  115. // Allows a person to enter his/her telephone number
  116. Scanner five = new Scanner(System.in);
  117. System.out.println("Enter Telephone number:" );
  118. telephone_number = five.nextInt();
  119. System.out.println("Telephone number accepted " + telephone_number);
  120. }
  121. }
  122.  
  123. Scanner input = new Scanner(System.in);
  124.  
  125. Scanner input = new Scanner(System.in);
  126.  
  127. System.out.println("Please enter your name: ");
  128. s = input.next(); // Getting a String value
  129.  
  130. System.out.println("Please enter your age: ");
  131. i = input.nextInt(); // Getting an integer
  132.  
  133. System.out.println("Please enter your salary: ");
  134. d = input.nextDouble(); // Getting a double
  135.  
  136. import java.util.Scanner;
  137.  
  138. public class Example
  139. {
  140. public static void main(String[] args)
  141. {
  142. int number1, number2, sum;
  143.  
  144. Scanner input = new Scanner(System.in);
  145.  
  146. System.out.println("Enter First multiple");
  147. number1 = input.nextInt();
  148.  
  149. System.out.println("Enter second multiple");
  150. number2 = input.nextInt();
  151.  
  152. sum = number1 * number2;
  153.  
  154. System.out.printf("The product of both number is %d", sum);
  155. }
  156. }
  157.  
  158. java.util.Scanner input = new java.util.Scanner(System.in);
  159. String userName;
  160. final int validLength = 6; // This is the valid length of an user name
  161.  
  162. System.out.print("Please enter the username: ");
  163. userName = input.nextLine();
  164.  
  165. while(userName.length() < validLength) {
  166.  
  167. // If the user enters less than validLength characters
  168. // ask for entering again
  169. System.out.println(
  170. "nUsername needs to be " + validLength + " character long");
  171.  
  172. System.out.print("nPlease enter the username again: ");
  173. userName = input.nextLine();
  174. }
  175.  
  176. System.out.println("Username is: " + userName);
  177.  
  178. Scanner scanner = new Scanner(System.in);
  179. String input = scanner.nextLine();
  180.  
  181. if (args.length != 2) {
  182. System.err.println("Utilizare: java Grep <fisier> <cuvant>");
  183. System.exit(1);
  184. }
  185. try {
  186. grep(args[0], args[1]);
  187. } catch (IOException e) {
  188. System.out.println(e.getMessage());
  189. }
  190.  
  191. import java.util.*;
  192.  
  193. class Ss
  194. {
  195. int id, salary;
  196. String name;
  197.  
  198. void Ss(int id, int salary, String name)
  199. {
  200. this.id = id;
  201. this.salary = salary;
  202. this.name = name;
  203. }
  204.  
  205. void display()
  206. {
  207. System.out.println("The id of employee:" + id);
  208. System.out.println("The name of employye:" + name);
  209. System.out.println("The salary of employee:" + salary);
  210. }
  211. }
  212.  
  213. class employee
  214. {
  215. public static void main(String args[])
  216. {
  217. Scanner sc = new Scanner(System.in);
  218.  
  219. Ss s = new Ss(sc.nextInt(), sc.nextInt(), sc.nextLine());
  220. s.display();
  221. }
  222. }
  223.  
  224. import java.util.Scanner;
  225.  
  226. public class App {
  227. public static void main(String[] args) {
  228. Scanner input = new Scanner(System.in);
  229. final int valid = 6;
  230.  
  231. Scanner one = new Scanner(System.in);
  232. System.out.println("Enter your username: ");
  233. String s = one.nextLine();
  234.  
  235. if (s.length() < valid) {
  236. System.out.println("Enter a valid username");
  237. System.out.println(
  238. "User name must contain " + valid + " characters");
  239. System.out.println("Enter again: ");
  240. s = one.nextLine();
  241. }
  242.  
  243. System.out.println("Username accepted: " + s);
  244.  
  245. Scanner two = new Scanner(System.in);
  246. System.out.println("Enter your age: ");
  247. int a = two.nextInt();
  248. System.out.println("Age accepted: " + a);
  249.  
  250. Scanner three = new Scanner(System.in);
  251. System.out.println("Enter your sex: ");
  252. String sex = three.nextLine();
  253. System.out.println("Sex accepted: " + sex);
  254. }
  255. }
  256.  
  257. Scanner obj= new Scanner(System.in);
  258. String s = obj.nextLine();
  259.  
  260. Scanner scan = new Scanner(System.in);
  261. String s = scan.nextLine();
  262. System.out.println("String: " + s);
  263.  
  264. import java.util.Scanner;
  265.  
  266. public class ScannerDemo {
  267.  
  268. public static void main(String[] args) {
  269. Scanner sc = new Scanner(System.in);
  270.  
  271. // Reading of Integer
  272. int number = sc.nextInt();
  273.  
  274. // Reading of String
  275. String str = sc.next();
  276. }
  277. }
  278.  
  279. public Scanner(InputStream source) {
  280. this(new InputStreamReader(source), WHITESPACE_PATTERN);
  281. }
  282.  
  283. public InputStreamReader(InputStream in) {
  284. super(in);
  285. try {
  286. sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## Check lock object
  287. }
  288. catch (UnsupportedEncodingException e) {
  289. // The default encoding should always be available
  290. throw new Error(e);
  291. }
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement