Guest User

Untitled

a guest
Feb 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. System.out.println("enter numerical value");
  2. int option;
  3. option = input.nextInt();//read numerical value from input
  4. System.out.println("enter 1st string");
  5. String string1 = input.nextLine();//read 1st string (this is skipped)
  6. System.out.println("enter 2nd string");
  7. String string2 = input.nextLine();//read 2nd string (this appears right after reading numerical value)
  8.  
  9. Enter numerical value
  10. 3 //this is my input
  11. enter 1st string //the program is supposed to stop here and wait for my input, but is skipped
  12. enter 2nd string //and this line is executed and waits for my input
  13.  
  14. int option = input.nextInt();
  15. input.nextLine(); // Consume newline left-over
  16. String str1 = input.nextLine();
  17.  
  18. int option = 0;
  19. try {
  20. option = Integer.parseInt(input.nextLine());
  21. } catch (NumberFormatException e) {
  22. e.printStackTrace();
  23. }
  24. String str1 = input.nextLine();
  25.  
  26. System.out.print("Insert a number: ");
  27. int number = input.nextInt();
  28. input.nextLine(); // This line you have to add (It consumes the n character)
  29. System.out.print("Text1: ");
  30. String text1 = input.nextLine();
  31. System.out.print("Text2: ");
  32. String text2 = input.nextLine();
  33.  
  34. int number = Integer.parseInt(input.nextLine());
  35.  
  36. int num1 = sc.nextInt();
  37. int num2 = sc.nextInt();
  38. String name = sc.next();
  39.  
  40. public static Scanner input = new Scanner(System.in);
  41.  
  42. public static void main(String[] args)
  43. {
  44. System.out.print("Insert a number: ");
  45. int number = input.nextInt();
  46. System.out.print("Text1: ");
  47. String text1 = input.next();
  48. System.out.print("Text2: ");
  49. String text2 = input.next();
  50. }
  51.  
  52. Scanner scanner = new Scanner(System.in);
  53. int option = scanner.nextInt();
  54. scanner.nextLine(); //clearing the buffer
  55.  
  56. class ScanReader {
  57. /**
  58. * @author Nikunj Khokhar
  59. */
  60. private byte[] buf = new byte[4 * 1024];
  61. private int index;
  62. private BufferedInputStream in;
  63. private int total;
  64.  
  65. public ScanReader(InputStream inputStream) {
  66. in = new BufferedInputStream(inputStream);
  67. }
  68.  
  69. private int scan() throws IOException {
  70. if (index >= total) {
  71. index = 0;
  72. total = in.read(buf);
  73. if (total <= 0) return -1;
  74. }
  75. return buf[index++];
  76. }
  77. public char scanChar(){
  78. int c=scan();
  79. while (isWhiteSpace(c))c=scan();
  80. return (char)c;
  81. }
  82.  
  83.  
  84. public int scanInt() throws IOException {
  85. int integer = 0;
  86. int n = scan();
  87. while (isWhiteSpace(n)) n = scan();
  88. int neg = 1;
  89. if (n == '-') {
  90. neg = -1;
  91. n = scan();
  92. }
  93. while (!isWhiteSpace(n)) {
  94. if (n >= '0' && n <= '9') {
  95. integer *= 10;
  96. integer += n - '0';
  97. n = scan();
  98. }
  99. }
  100. return neg * integer;
  101. }
  102.  
  103. public String scanString() throws IOException {
  104. int c = scan();
  105. while (isWhiteSpace(c)) c = scan();
  106. StringBuilder res = new StringBuilder();
  107. do {
  108. res.appendCodePoint(c);
  109. c = scan();
  110. } while (!isWhiteSpace(c));
  111. return res.toString();
  112. }
  113.  
  114. private boolean isWhiteSpace(int n) {
  115. if (n == ' ' || n == 'n' || n == 'r' || n == 't' || n == -1) return true;
  116. else return false;
  117. }
  118.  
  119. public long scanLong() throws IOException {
  120. long integer = 0;
  121. int n = scan();
  122. while (isWhiteSpace(n)) n = scan();
  123. int neg = 1;
  124. if (n == '-') {
  125. neg = -1;
  126. n = scan();
  127. }
  128. while (!isWhiteSpace(n)) {
  129. if (n >= '0' && n <= '9') {
  130. integer *= 10;
  131. integer += n - '0';
  132. n = scan();
  133. }
  134. }
  135. return neg * integer;
  136. }
  137.  
  138. public void scanLong(long[] A) throws IOException {
  139. for (int i = 0; i < A.length; i++) A[i] = scanLong();
  140. }
  141.  
  142. public void scanInt(int[] A) throws IOException {
  143. for (int i = 0; i < A.length; i++) A[i] = scanInt();
  144. }
  145.  
  146. public double scanDouble() throws IOException {
  147. int c = scan();
  148. while (isWhiteSpace(c)) c = scan();
  149. int sgn = 1;
  150. if (c == '-') {
  151. sgn = -1;
  152. c = scan();
  153. }
  154. double res = 0;
  155. while (!isWhiteSpace(c) && c != '.') {
  156. if (c == 'e' || c == 'E') {
  157. return res * Math.pow(10, scanInt());
  158. }
  159. res *= 10;
  160. res += c - '0';
  161. c = scan();
  162. }
  163. if (c == '.') {
  164. c = scan();
  165. double m = 1;
  166. while (!isWhiteSpace(c)) {
  167. if (c == 'e' || c == 'E') {
  168. return res * Math.pow(10, scanInt());
  169. }
  170. m /= 10;
  171. res += (c - '0') * m;
  172. c = scan();
  173. }
  174. }
  175. return res * sgn;
  176. }
  177.  
  178. }
  179.  
  180. import java.io.BufferedInputStream;
  181. import java.io.IOException;
  182. import java.io.InputStream;
  183. class Main{
  184. public static void main(String... as) throws IOException{
  185. ScanReader sc = new ScanReader(System.in);
  186. int a=sc.scanInt();
  187. System.out.println(a);
  188. }
  189. }
  190. class ScanReader....
  191.  
  192. Scanner stringScanner = new Scanner(System.in);
  193. Scanner intScanner = new Scanner(System.in);
  194.  
  195. intScanner.nextInt();
  196. String s = stringScanner.nextLine(); // unaffected by previous nextInt()
  197. System.out.println(s);
  198.  
  199. intScanner.close();
  200. stringScanner.close();
  201.  
  202. public static void main(String[] args) {
  203. Scanner scan = new Scanner(System.in);
  204. int i = scan.nextInt();
  205. scan.nextLine();
  206. double d = scan.nextDouble();
  207. scan.nextLine();
  208. String s = scan.nextLine();
  209.  
  210. System.out.println("String: " + s);
  211. System.out.println("Double: " + d);
  212. System.out.println("Int: " + i);
  213. }
  214.  
  215. int firstNumber = input.nextInt();
  216. int secondNumber = input.nextInt();
  217.  
  218. int i = new Scanner(System.in).nextInt();
Add Comment
Please, Sign In to add comment