/** * This method returns the entire result from the HTTP response. * * @param url The URL to fetch the HTTP response from. * @return The contents of the HTTP response. * @throws IOException Related to network and stream reading */ public static String getResponseFromHttpUrl(URL url) throws IOException { HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { InputStream in = urlConnection.getInputStream(); Scanner scanner = new Scanner(in); scanner.useDelimiter("\\A"); boolean hasInput = scanner.hasNext(); if (hasInput) { return scanner.next(); } else { return null; } } finally { urlConnection.disconnect(); } }
public static void main(String[] args) { //get input Scanner sc = new Scanner(System.in).useDelimiter(" "); ArrayList<Integer> input = new ArrayList<>(); //add input to ArrayList while (sc.hasNextInt()) { input.add(sc.nextInt()); } //sort the list Collections.sort(input); //initialize closest values, with the first two elements in the list int closest = input.get(1)-input.get(0); //check all elements in the list for(int i = 2; i < input.size(); i++) { //change closest if we find two elements with a shorter distance. closest = Math.min(closest, input.get(i)-input.get(i-1)); } //print the shortest distance System.out.println(closest); }
public static ArrayList<String[]> secondList(){ try{ Scanner scannerSongs = new Scanner(new File("Recommended_db.csv")); ArrayList<String[]> allSongs = new ArrayList<>(); scannerSongs.nextLine(); while (scannerSongs.hasNextLine()) { String line = scannerSongs.nextLine(); String[] columns = line.split(","); String[] songInfo = {columns[3],columns[4],null}; allSongs.add(songInfo); } return allSongs; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
public static void main(String[] args) { // entrada = 3 notas // Seria o prompt do java script Scanner sc = new Scanner(System.in); System.out.println("Digite o valor da nota 1:"); double nota1 = sc.nextDouble(); System.out.println("Digite o valor da nota 2:"); double nota2 = sc.nextDouble(); System.out.println("Digite o valor da nota 3:"); double nota3 = sc.nextDouble(); // processamento = calcular media double media = (nota1 + nota2 + nota3)/3; // saida = condicao do aluno (Reprovado, aprovado, recuperacao) if (media <= 5) { System.out.println("Reprovado"); } else if (media > 5 && media < 7) { System.out.println("Recuperacao"); } else { System.out.println("Aprovado"); } }
public static String getResponseFromHttpUrl(String url) throws IOException { URL urlObject = new URL(url); HttpURLConnection urlConnection = (HttpURLConnection) urlObject.openConnection(); try { InputStream in = urlConnection.getInputStream(); Scanner scanner = new Scanner(in); scanner.useDelimiter("\\A"); boolean hasInput = scanner.hasNext(); if (hasInput) { return scanner.next(); } else { return null; } } finally { urlConnection.disconnect(); } }
public static void main(String[] args) { Scanner x = new Scanner(System.in); PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out)); int n = x.nextInt(), c; int a[] = new int[701]; for (int i = 0; i < n; i++) { c = x.nextInt(); a[c]++; } int s = 0; for (int i = 600; i < a.length; i++) { s += a[i] / 4; } writer.print(s); writer.close(); }
public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); Byte n = in.nextByte(); double ans = 0; double a[] = new double[n]; for (int i = 0; i < a.length; i++) { a[i] = in.nextInt(); } Arrays.sort(a); ans = a[a.length - 1]; for (int i = a.length - 1; i > 0; i--) { ans = Max(ans, a[i - 1]); } System.out.printf("%.2f", ans); }
/** * @generated NOT */ @Override public TimeInterval createTimeIntervalFromString(final String value) { final TimeIntervalImpl anInterval = new TimeIntervalImpl(); final Scanner scan = new Scanner(value); final String leftPar = scan.findInLine("\\]|\\["); anInterval.setMinOpen("]".equals(leftPar)); final String leftStr = scan.findInLine("[^,]*"); anInterval.setMin(createDurationFromString(leftStr)); scan.findInLine(","); String rightStr = scan.findInLine("[^\\]\\[]*"); if (rightStr == null) { rightStr = leftStr; } anInterval.setMax(createDurationFromString(rightStr)); final String rightPar = scan.findInLine("\\]|\\["); anInterval.setMaxOpen("[".equals(rightPar)); scan.close(); return anInterval; }
/** * This method returns the entire result from the HTTP response. * * @param url The URL to fetch the HTTP response from. * @return The contents of the HTTP response, null if no response * @throws IOException Related to network and stream reading */ public static String getResponseFromHttpUrl(URL url) throws IOException { HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { InputStream in = urlConnection.getInputStream(); Scanner scanner = new Scanner(in); scanner.useDelimiter("\\A"); boolean hasInput = scanner.hasNext(); String response = null; if (hasInput) { response = scanner.next(); } scanner.close(); return response; } finally { urlConnection.disconnect(); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int number = in.nextInt(); int reserve = 0; int result = 0; int temp; for (int i = 0; i < number; i++) { temp = in.nextInt(); if (temp == -1 && reserve > 0) reserve--; else if (temp == -1 && reserve == 0) result++; else if (temp > 0) reserve += temp; } System.out.print(result); }
private void startCommandHandlerOnNewThread() { Log.info("NOTE: you can now type commands here."); CommandHandler commandHandler = new CommandHandler(); Runnable commandHandlingTask = () -> { try (Scanner scanner = new Scanner(System.in)) { while (true) { String command = scanner.nextLine(); commandHandler.handle(command); } } }; new Thread(commandHandlingTask).start(); }
/** * Gets the OS version string from a Linux release-specific file. */ private String getVersionString(File f){ try { Scanner sc = new Scanner(f); return sc.findInLine("(\\d)+((\\.)(\\d)+)*"); } catch (Exception e){ } return null; }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int length = in.nextInt(); int speed1 = in.nextInt(); int speed2 = in.nextInt(); double time = (double) length / (speed1 + speed2); System.out.print(time * speed1); }
/** * Handles Xml file and public dejagnu test results from this. * * @param xmlFile file with test results * @return count of public xmlFile has been handled */ int handleXmlResults(@NotNull final File xmlFile){ myTestsCount = 0; try { String xmlEntry = new Scanner(xmlFile, "UTF-8").useDelimiter("\\A").next(); if (myNeedReplaceApm){ xmlEntry = replaceAmp(replaceXmlHeaderVersion(xmlEntry)); } if (myNeedToReplaceControls){ xmlEntry = replaceControlChars(xmlEntry); } parseXmlTestResults(xmlEntry, xmlFile.getAbsolutePath()); return myTestsCount; } catch (final FileNotFoundException ignored){ //e.getMessage(); return 0; } }
public static void main(String [] args) { Scanner input = new Scanner(System.in); int sayi; String metin; /* system.out.println("Randevu adi giriniz : "); metin = input.next(); system.out.println("Randevu yeri giriniz : "); metin = input.nextLine(); system.out.print("Randevu tarih-saati giriniz : " + metin); sayi = input.nextLine(); System.out.println("Randevunuz = " + randevu); System.out.println("Yeriniz = " + yer); System.out.println("Tarihiniz = " + tarih); getchar(); return 0; */ }
public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Type the first number: "); int firstNumber = Integer.parseInt(reader.nextLine()); System.out.print("Type the second number: "); int secondNumber = Integer.parseInt(reader.nextLine()); System.out.println(""); if ( firstNumber > secondNumber ) { System.out.println("Greater number: " + firstNumber); } else if (firstNumber < secondNumber) { System.out.println("Greater number: " + secondNumber); } else { System.out.println("The numbers are equal!"); } }
/** * init. * @param socket - ip * @throws IOException - IOException */ public void init(Socket socket) throws IOException { String message; PrintWriter out = new PrintWriter(socket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); Scanner console = new Scanner(System.in); do { message = console.nextLine(); out.println(message); String str; if (!EXIT.equals(message)) { while (!(str = in.readLine()).isEmpty()) { System.out.println(str); } } } while (!EXIT.equals(message)); }
public static void main(String[] args) { // create a Scanner object to obtain input from the command window Scanner input = new Scanner(System.in); // create an Account object and assign it to myAccount Account myAccount = new Account(); // display initial value of name (null) System.out.printf("Initial name is: %s%n%n", myAccount.getName()); // prompt for and read name System.out.println("Please enter the name:"); String theName = input.nextLine(); // read a line of text myAccount.setName(theName); // put theName in myAccount System.out.println(); // outputs a blank line // display the name stored in object myAccount System.out.printf("Name in object myAccount is:%n%s%n", myAccount.getName()); }
public static void main(String[] args) { Scanner sc =new Scanner(System.in); System.out.println("************登录菜单************\n1、登录系统\n2、退出"); int a1 = sc.nextInt(); if(a1 == 1) { System.out.println("************主菜单************\n" + "1、客户管理系统\n2、购物结算\n3、真情回馈\n4、注销"); int a2 = sc.nextInt(); switch(a2) { case 1: System.out.println("购物管理系统>客户信息管理\n" + "1、显示所有客户信息\n2、添加客户信息\n3、修改客户信息\n4、查询客户信息"); break; case 2: break; case 3: System.out.println("购物管理系统>真情回馈\n" + "1、幸运大放送\n2、幸运抽奖\n3、生日问候"); break; case 4: break; } } sc.close(); }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int newCandle = in.nextInt(); int oldCandle = in.nextInt(); int hours = newCandle; int temp, remainder; temp = newCandle / oldCandle; remainder = newCandle % oldCandle; while (temp > 0) { hours += temp; newCandle = temp + remainder; temp = newCandle / oldCandle; remainder = newCandle % oldCandle; } System.out.print(hours); }
public static void main(String[] args) { Scanner s = new Scanner(System.in); int num = 500000; // Test values double[] test_a = { 30, -40, 36 }; //InvQuadRegression qr = new InvQuadRegression(list.size()); InvQuadRegression qr = new InvQuadRegression(num); // Seed qr with random stuff. for (int i = 0; i < num; i++) { int n = (int) (15*Math.random())+1; double th = cal_thr(test_a, n);// + .1*Math.random(); qr.add(n, 1/(th*th)); } double[] a = qr.calculate(); }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = 10; int[] box = new int[n]; box[0] = scanner.nextInt(); boolean flag = false; for (int i = 1; i < n; i++) { box[i] = scanner.nextInt(); if (!flag) { if (box[i] != 0) { System.out.print(i); box[i]--; flag = true; } } } for (int i = 0; i < n; i++) { if (box[i] != 0) { for (int j = 0; j < box[i]; j++) { System.out.print(i); } } } }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); Vistor vister = new Vistor(); for (int i = 0; i < 10; i++) { System.out.println("请输入姓名"); vister.name = sc.next(); if ("n".equals(vister.name)) { System.out.println("退出程序"); break; } System.out.println("请输入年龄"); vister.age = sc.nextInt(); vister.show(); } sc.close(); }
private static String getWindowsIdentifier() throws IOException, NoSuchAlgorithmException { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(new String[] { "wmic", "csproduct", "get", "UUID" }); String result = null; InputStream is = process.getInputStream(); Scanner sc = new Scanner(process.getInputStream()); try { while (sc.hasNext()) { String next = sc.next(); if (next.contains("UUID")) { result = sc.next().trim(); break; } } } finally { is.close(); } return result==null?UNKNOWN:Utils.hexStringify(Utils.sha256Hash(result.getBytes())); }
private static String readTweetLongedText(String id) { StringBuilder sb = new StringBuilder(); try { Scanner scanner = new Scanner(new BufferedInputStream( new URL("http://www.twitlonger.com/api_read/" + id).openStream())); while (scanner.hasNext()) sb.append(scanner.nextLine()); scanner.close(); return new TwitLongerResponse(sb.toString()).content; } catch (IOException e) { Timber.i("", e); } return sb.toString(); }
public static void main(String[] args) { //从控制台输入会员积分 Scanner sc = new Scanner(System.in); System.out.print("请输入会员积分:"); int point = sc.nextInt(); sc.close(); //判断会员积分所属区间,输出相应折扣 if (point < 2000) { System.out.println("该会员享受的的折扣是:9折"); } else if (point < 4000) { System.out.println("该会员享受的的折扣是:8折"); } else if (point < 8000) { System.out.println("该会员享受的的折扣是:7折"); } else { System.out.println("该会员享受的的折扣是:6折"); } }
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 0; i < t; i++) { try { long x = scan.nextLong(); System.out.println(x + " can be fitted in:"); if (x >= Byte.MIN_VALUE && x <= Byte.MAX_VALUE) { System.out.println("* byte"); } if (x >= Short.MIN_VALUE && x <= Short.MAX_VALUE) { System.out.println("* short"); } if (x >= Integer.MIN_VALUE && x <= Integer.MAX_VALUE) { System.out.println("* int"); } if (x >= Long.MIN_VALUE && x <= Long.MAX_VALUE) { System.out.println("* long"); } } catch (Exception e) { System.out.println(scan.next() + " can't be fitted anywhere."); } } scan.close(); }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); int middle = size / 2; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i <= middle) { if (j <= middle + i && j >= middle - i) System.out.print("D"); else System.out.print("*"); } else { if (j <= size - (i - middle) - 1 && j >= i - middle) System.out.print("D"); else System.out.print("*"); } } System.out.println(); } }
public static void main(String[] args) { Scanner leitor = new Scanner(System.in); Pilha pilha = new Pilha(); String msg = "1 - Adiciona\n2 - Remove\n3 - Exibe\n9 - Sair"; int opc, e; do { System.out.println(msg); opc = leitor.nextInt(); switch (opc) { case 1: System.out.print("Elemento: "); e = leitor.nextInt(); pilha.adiciona(e); break; case 2: System.out.println("Removido: " + pilha.remove()); break; case 3: pilha.exibe(); break; } } while(opc != 9); }
public static void main(String []args)throws IllegalArgumentException { Scanner sc=new Scanner(System.in); System.out.println("Enter a number whose fctorial need to be found"); int x=sc.nextInt(); long fac=0; try{ if(x>20) throw new IllegalArgumentException(x); if(x<0) throw new IllegalArgumentException(); fac=fact(x); System.out.println("Factorial of "+x+" is : "+fac); } catch(Exception e) /*For exceptions other than range specification*/ { System.out.println(e); System.out.println("Factorial can't be calculated because of some exception."); } }
private List<String> getCharacterArray() { List<String> chars_array = new ArrayList<String>(); String file = "assets/unicode_codepoints.csv"; Scanner scanner = new Scanner(getClass().getClassLoader().getResourceAsStream(file), "UTF-8"); int i = 0; String currentUnicode = null; try { while (scanner.hasNextLine()) { currentUnicode = scanner.nextLine(); char[] chars = Character.toChars(Integer.parseInt(currentUnicode, 16)); String codePoint = new String(chars); chars_array.add(codePoint); i++; } } catch (Exception e) { fail("Failure, Codepoint: " + i + " / " + currentUnicode + " " + e.getMessage()); } return chars_array; }
public static void main(String[] args) { Scanner input = new Scanner(System.in); double radius, height, vol; System.out.print("Raio do Cilindro: "); radius = input.nextDouble(); System.out.print("Altura do Cilindro: "); height = input.nextDouble(); input.close(); vol = (Math.PI * Math.pow(radius, 2)) * height; System.out.printf("Volume do Cilindro: %.2f\n", vol); }
public static void main(String[] args) { Scanner reader = new Scanner(System.in); // Type your program here: System.out.print("Type a number: "); int number = Integer.parseInt(reader.nextLine()); System.out.println(""); if (number > 0) { System.out.println("The number is positive."); } else { System.out.println("The number is not positive."); } }
@Test public void assureInputFromUser() throws Exception { final AddMojo mojo = getMojoFromPom(); final AddMojo mojoSpy = spy(mojo); final Scanner scanner = mock(Scanner.class); doReturn("2").when(scanner).nextLine(); doReturn(scanner).when(mojoSpy).getScanner(); final Set<String> set = new HashSet<>(); mojoSpy.assureInputFromUser("property", "", Arrays.asList("a0", "a1", "a2"), set::add); assertTrue(set.contains("a2")); }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long a = scanner.nextLong(); long b = scanner.nextLong(); long timeResult = Math.round((b - a) / 100.0); System.out.printf("%02d:%02d:%02d", timeResult / 3600, (timeResult / 60) % 60, timeResult % 60); // System.out.print(+":"++":"+); }
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int m = scan.nextInt(); int n = scan.nextInt(); double [][] X = new double[n][m + 1]; double [][] Y = new double[n][1]; for (int row = 0; row < n; row++) { X[row][0] = 1; for (int col = 1; col <= m; col++) { X[row][col] = scan.nextDouble(); } Y[row][0] = scan.nextDouble(); } /* Calculating B */ double [][] xtx = multiply(transpose(X),X); double [][] xtxInv = invert(xtx); double [][] xty = multiply(transpose(X), Y); double [][] B = multiply(xtxInv, xty); int sizeB = B.length; /* Calculating values for "q" feature sets */ int q = scan.nextInt(); for (int i = 0; i < q; i++) { double result = B[0][0]; for (int row = 1; row < sizeB; row++) { result += scan.nextDouble() * B[row][0]; } System.out.println(result); } scan.close(); }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int[] chars = new int[26]; String a = scanner.next(); String b = scanner.next(); int n = a.length(); if (n != b.length()) { System.out.println("NO"); } else { for (int j = 0; j < n; j++) { chars[a.charAt(j) - 'a']++; chars[b.charAt(j) - 'a']--; } boolean found = true; for (int j = 0; j < 26; j++) { if (chars[j] != 0) { System.out.println("NO"); found = false; break; } } if (found) { System.out.println("YES"); } } } }
/** * * @param model modello partita offline */ public PartitaOfflineConsoleView(PartitaOfflineModel model) { this.listeners = new CopyOnWriteArrayList<>(); this.model = model; this.model.addObserver(this); scanner = new Scanner(System.in); }
@Test public void adoptPet() { Scanner input = new Scanner(System.in); LOGGER.info("欢迎光临宠物乐园"); LOGGER.info("请输入登录名:"); String username = input.next(); LOGGER.info("请输入密码:"); String password = input.next(); Master master = new Master(username, password); MasterDao mas = new MasterDaoImpl(session, tx); MasterServiceImpl masterService = new MasterServiceImpl(mas); if(masterService.login(master)) { LOGGER.info("登录成功!"); Pet pet = new Pet(); pet.setName("旺财"); pet.setMaster(master); PetType pt = new PetType(); pt.setName("狗狗"); session.persist(pt); pet.setPetType(pt); masterService.adoptPet(pet); } else { LOGGER.info("登录失败!"); } }