public static void main(String[] args) { System.out.print("Por favor, introduce el primer número "); String linea; linea = System.console().readLine(); int primerNumero; primerNumero = Integer.parseInt(linea); System.out.print("Introduce el segundo número "); linea = System.console().readLine(); int segundoNumero; segundoNumero = Integer.parseInt(linea); int total1; total1 = (primerNumero + segundoNumero); System.out.print("La suma del primer número mas el segundo es "); System.out.println(total1); int total2; total2 = (primerNumero - segundoNumero); System.out.print("La resta del primer número menos el segundo es "); System.out.println(total2); int total3; total3 = (primerNumero * segundoNumero); System.out.print("La multiplicación del primer numero por el segundo es "); System.out.println(total3); double total4; total4 = ((double) primerNumero / segundoNumero); System.out.print("La división entre los dos número es "); System.out.print(total4); }
public static void main(String[] args) { System.out.println("Vámos a ordenar 3 números introducidos"); System.out.println("--------------------------------------"); System.out.print("Introduce el primer número: "); int num1 = Integer.parseInt(System.console().readLine()); System.out.print("Introduce el segundo número: "); int num2 = Integer.parseInt(System.console().readLine()); int aux = 0; if (num2 < num1) { aux = num1; num1 = num2; num2 = aux; } System.out.print("Introduce el tercer número: "); int num3 = Integer.parseInt(System.console().readLine()); if ((num3) < (num1)) { aux = num1; num1 = num3; num3 = num2; num2 = aux; } else if ((num3) < (num2)) { aux = num2; num2 = num3; num3 = aux; } System.out.print("Números introducidos ordenados: "); System.out.print(num1 + ", " + num2 + ", " + num3); }
public static void main(String[] args) { caluculator caluculator_object = new caluculator(); System.out.println("Please enter the two numbers you would like to work with"); int a = Integer.parseInt(System.console().readLine()); int b = Integer.parseInt(System.console().readLine()); System.out.println("what would you like to do today?"); System.out.println("1 - add"); System.out.println("2 - subtract"); System.out.println("3 - multiply"); System.out.println("4 - divide"); int n = Integer.parseInt(System.console().readLine()); switch (n) { case 1: System.out.println(caluculator_object.add(a, b)); break; case 2: System.out.println(caluculator_object.subtract(a, b)); break; case 3: System.out.println(caluculator_object.multiply(a, b)); break; case 4: System.out.println(caluculator_object.divide(a, b)); break; } }
public static void main(String[] args) { Employees emp = new Employees(); for (int i = 0; i < 10; i++) { System.out.println("Please key in employee name: "); String str = System.console().readLine(); System.out.println("Please key in employee ID: "); String sID = System.console().readLine(); int idNum = Integer.parseInt(sID); emp.setName(str, i); emp.setID(idNum, i); } System.out.println("Employees with ID numbers smaller than 1,000: "); for (int i = 0; i < 10; i++) { if (emp.getID(i) < 1000) { System.out.println("Name: " + emp.getName(i) + " ID: " + emp.getID(i)); } } System.out.println("Employees with names that start with J or S: "); for (int i = 0; i < 10; i++) { String empName = emp.getName(i); if (empName.charAt(0) == 'J' || empName.charAt(0) == 'S') { System.out.println("Name: " + emp.getName(i) + " ID: " + emp.getID(i)); } } }
public static void main(String[] args) { boolean run = true; try { // build a raw TCP and UDP socket for testing tcpSocket = new TCP_Sock(userRegPort, false); udpSocket = new UDP_Sock(gamePort, true); System.out.println("Enter server IP:"); serverIp = System.console().readLine(); System.out.println("Connecting to: " + serverIp); if (!tcpSocket.connect(serverIp)) { System.out.println("Error connecting to: " + serverIp); tcpSocket.getLastException().printStackTrace(); throw new IOException("Failed to connect to server"); } System.out.println("Triva Server Test Client\n1-TCP\n2-UDP\n3-quit"); while (run) { int command = -1; int selection = Integer.parseInt(System.console().readLine()); switch (selection) { case 1: System.out.println("Select a TCP command to send"); System.out.println( "0-Check Server\n1-Register User\n2-Deregister User\n3-Ready\n4-Not Ready"); command = Integer.parseInt(System.console().readLine()); if (command > -1 && command < 5) { System.out.println("Sending message"); tcpSocket.send(createMsg(command, true)); if (command != 3 && command != 4) printMsg(serverIp, tcpSocket.receive(), true); } else System.out.println("Invalid command"); break; case 2: System.out.println("Select a UDP command to send"); System.out.println("1-Buzzer"); command = Integer.parseInt(System.console().readLine()); if (command != 1) { System.out.println("Sending message"); udpSocket.send(createMsg(command, false), serverIp); } else System.out.println("Invalid command"); break; case 3: System.out.println("Closing Client"); run = false; break; default: System.out.println("Invalid command"); break; } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public boolean gestion() throws SQLException { out.clear(); int choix = listeChoix(); switch (choix) { case 1: out.clear(); out.afficheRes( conn.infoColis( lireEntier("Entrez l'Id du colis dont vous voulez les infos\n", "vert"), this.id)); break; case 2: out.clear(); out.afficheRes(conn.listeProduits(false)); break; case 3: out.clear(); conn.setDateLivraison(lireEntier("Entrez l'Id d'une commande", "vert"), lireDate()); break; case 4: String login, mdp; do { out.ecrire("Verifions vos identifiants actuels, Entrez votre login: \n", "vert"); if (!this.login.equals(System.console().readLine())) { out.ecrire("Erreur, votre login ne correspond pas !\n", "violet"); break; } out.ecrire("Votre mot de passe actuel ?"); if (!this.mdp.equals(System.console().readLine())) { out.ecrire("Erreur, votre mot de passe ne correspond pas !\n", "violet"); break; } out.ecrire("Entrez votre nouveau login\n", "vert"); login = System.console().readLine(); out.ecrire("Entrez votre nouveau mot de passe\n", "vert"); mdp = new String(System.console().readPassword()); } while (conn.changeIdentifiants(this.id, mdp, login) != 0); break; case 5: int idProd = lireEntier("Entrez l'ID du produit que vous voulez commander\n", "vert"); int quantite = lireEntier("Entrez la quantité voulu\n", "vert"); out.ecrire("Date de livraison\n", "bleu"); String date = lireDate(); if (conn.creerCommande(this.id, idProd, quantite, date) != 0) { out.ecrire("Pas assez de produits disponibles", "violet"); break; } out.ecrire("Commande passée !\n", "rouge"); break; default: out.ecrire("Veuillez choisir parmis les choix proposés\n"); break; } return fin(); }
public static void main(String[] args) { System.out.print("Introduzca un número: "); long n = Long.parseLong(System.console().readLine()); System.out.print("Introduzca el número de rotaciones a la derecha: "); int r = Integer.parseInt(System.console().readLine()); System.out.print("El número rotado es " + rotaNumeroDerecha(n, r)); }
public static String getInput(String question, boolean mask) { System.out.println(question + " "); if (mask) { char[] passwordChars = System.console().readPassword(); return new String(passwordChars); } else { return System.console().readLine(); } }
public static void main(String[] args) { // enter version numbers System.out.println("Enter version 1:"); float ver1 = Float.parseFloat(System.console().readLine()); System.out.println("Enter version 2:"); float ver2 = Float.parseFloat(System.console().readLine()); int result = compareVersions(ver1, ver2); System.out.println("The results is :" + result); }
public static void main(String args) throws InterruptedException { ModelExecutor executor = ModelExecutor.create().setTraceLogging(false).launch(MicrowaveTester::init); String inp = ""; do { System.out.println("Do Action: "); inp = System.console().readLine(); inp = inp.toLowerCase(); switch (inp) { case "open": API.send(new Open(), m); break; case "close": API.send(new Close(), m); break; case "put": API.send(new Put(), m); break; case "get": API.send(new Get(), m); break; case "setintensity": API.log(" Intensity Level (1-5): "); Integer i = Integer.parseInt(System.console().readLine()); API.send(new SetIntensity(i), m); break; case "settime": API.log(" Time in sec(s): "); Integer t = Integer.parseInt(System.console().readLine()); API.send(new SetTime(t), m); break; case "start": API.send(new Start(), m); break; case "stop": API.send(new Stop(), m); break; case "quit": break; case "help": default: System.out.println( "Actions to use: Open, Close, Put, " + "Get, SetIntensity, SetTime, Start, Stop."); break; } } while (!inp.equals("quit")); executor.shutdown(); }
public static void main(String[] args) { int numero; int exponente; System.out.println("Introduzca un número entero: "); numero = Integer.parseInt(System.console().readLine()); System.out.println("Introduzca la potencia: "); exponente = Integer.parseInt(System.console().readLine()); System.out.println(matematicas.varios.potencia(exponente, numero)); }
public static void main(String[] args) { System.out.println("Enter your first number"); String s = System.console().readLine(); int xx = Integer.parseInt(s); System.out.println("Enter your first number"); String ss = System.console().readLine(); int yy = Integer.parseInt(s); System.out.println(xx + " plus " + yy + " = " + add(xx, yy)); System.out.println(xx + " subtracted " + yy + " = " + subtract(xx, yy)); System.out.println(xx + " multiply " + yy + " = " + multiply(xx, yy)); System.out.println(xx + " divided " + yy + " = " + divide(xx, yy)); }
public static void main(String[] args) { System.out.println("Este programa resuelve ecuaciones de primer grado del tipo ax + b = 0"); System.out.print("Por favor, introduzca el valor de a: "); Double a = Double.parseDouble(System.console().readLine()); System.out.print("Ahora introduzca el valor de b: "); Double b = Double.parseDouble(System.console().readLine()); if (a == 0) { System.out.println("Esa ecuación no tiene solución real."); } else { System.out.println("x = " + (-b / a)); } }
public static void main(String[] args) { System.out.print("Introduzca un número: "); long num = Long.parseLong(System.console().readLine()); System.out.print("Introduzca el número de veces que quiere rotarlo: "); int rotacion = Integer.parseInt(System.console().readLine()); System.out.print( "Su número rotado " + rotacion + " veces a la izquierda es el: " + funciones.Matematicas.rotaNumeroIzquierda(num, rotacion)); }
public static void main(String[] args) { System.out.print("Introduce un número entero: "); int numeroIntroducido = Integer.parseInt(System.console().readLine()); System.out.print("Introduce el dígito a añadir: "); int digitoañadir = Integer.parseInt(System.console().readLine()); int digitofinal = 0; numeroIntroducido *= 10; numeroIntroducido += digitoañadir; System.out.println("El resultado es: " + numeroIntroducido); }
public static void main(String[] args) { int n, digitos = 0; System.out.print("Por favor, introduzca un número entero (de 5 cifras como máximo): "); n = Math.abs(Integer.parseInt(System.console().readLine())); if (n < 10) { digitos = 1; } if ((n >= 10) && (n < 100)) { digitos = 2; } if ((n >= 100) && (n < 1000)) { digitos = 3; } if ((n >= 1000) && (n < 10000)) { digitos = 4; } if (n >= 10000) { digitos = 5; } System.out.println("El número introducido tiene " + digitos + " dígitos."); }
public static void main(String[] args) { System.out.println("Vamos a dibujar la letra U."); System.out.println("Por favor, introduzca la altura que desee que tenga: "); int altura = Integer.parseInt(System.console().readLine()); String simbolo = "*"; int espaciosInteriores = altura - 2; for (int i = 0; i < altura - 1; i++) { System.out.print(simbolo); for (int j = 0; j < espaciosInteriores; j++) { System.out.print(" "); } System.out.print(simbolo); System.out.println(); } System.out.print(" "); for (int k = 0; k < (altura - 2); k++) { System.out.print(simbolo); } }
// main method not found. runtime error. main method signature is not proper public static void main(String[] args) { Console mconsole = System.console(); // error: cannot find symbol String firstName = mconsole.readLine("What is your name"); }
/** * Evaluates arguments given by the user. * * @param args * @throws IOException */ Arguments(final String[] args) throws IOException { this.commandLine = new CommandLine(args[1], args.length > 2 ? args[2] : null); if (this.commandLine.hasInput() && this.commandLine.hasOutput()) { if (args.length < 5) { System.err.println( "You got to give both input and output file for the command:" + this.commandLine.showCommand()); System.exit(-1); // NOPMD, it's not a JEE app } this.inputFile = new File(args[3]).getCanonicalFile(); this.outputFile = new File(args[4]).getCanonicalFile(); } else if (this.commandLine.hasInput()) { if (args.length < 4) { System.err.println( "You got to give input file for the command:" + this.commandLine.showCommand()); System.exit(-1); // NOPMD, it's not a JEE app } this.inputFile = new File(args[3]).getCanonicalFile(); this.outputFile = null; } else if (this.commandLine.hasOutput()) { if (args.length < 4) { System.err.println( "You got to give output file for the command:" + this.commandLine.showCommand()); System.exit(-1); // NOPMD, it's not a JEE app } this.inputFile = null; this.outputFile = new File(args[3]).getCanonicalFile(); } else { this.inputFile = null; this.outputFile = null; } if (this.inputFile != null && !this.inputFile.isFile()) { System.err.println("Input file '" + this.inputFile.getPath() + "' does not exist."); System.exit(-1); // NOPMD, it's not a JEE app } if (this.inputFile != null && !this.inputFile.canRead()) { System.err.println("Input file '" + this.inputFile.getPath() + "' is not readable."); System.exit(-1); // NOPMD, it's not a JEE app } if (this.outputFile != null && this.outputFile.exists()) { System.err.println("Output file '" + this.outputFile.getPath() + "' does already exist."); System.exit(-1); // NOPMD, it's not a JEE app } final File outputDir = this.outputFile != null ? this.outputFile.getParentFile() : null; if (this.outputFile != null && !outputDir.isDirectory()) { System.err.println("Output directory '" + outputDir.getPath() + "' is not existing."); System.exit(-1); // NOPMD, it's not a JEE app } if (this.outputFile != null && !outputDir.canWrite()) { System.err.println("Output directory '" + outputDir.getPath() + "' is not writable."); System.exit(-1); // NOPMD, it's not a JEE app } if (this.commandLine.passwordPrompt != null) { System.err.print(this.commandLine.passwordPrompt); this.password = String.valueOf(System.console().readPassword()); System.err.println(); } else { this.password = null; } }
public static void main(String[] args) throws Exception { BioServer s = new BioServer(9999); s.start(); System.console().readLine("BioServer running on port 9999. Press enter to exit."); System.exit(0); s.stop(); }
public static void main(String[] args) throws MessagingException, IOException { Properties props = new Properties(); try (InputStream in = Files.newInputStream(Paths.get("mail", "mail.properties"))) { props.load(in); } List<String> lines = Files.readAllLines(Paths.get(args[0]), Charset.forName("UTF-8")); String from = lines.get(0); String to = lines.get(1); String subject = lines.get(2); StringBuilder builder = new StringBuilder(); for (int i = 3; i < lines.size(); i++) { builder.append(lines.get(i)); builder.append("\n"); } Console console = System.console(); String password = new String(console.readPassword("Password: ")); Session mailSession = Session.getDefaultInstance(props); // mailSession.setDebug(true); MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(from)); message.addRecipient(RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); message.setText(builder.toString()); Transport tr = mailSession.getTransport(); try { tr.connect(null, password); tr.sendMessage(message, message.getAllRecipients()); } finally { tr.close(); } }
public static void main(String[] args) { int N; System.out.println("Informe um numero:"); N = Integer.parseInt(System.console().readLine()); switch (N) { case 1: System.out.println("Domingo"); break; case 2: System.out.println("Segunda-feira"); break; case 3: System.out.println("Terca-feira"); break; case 4: System.out.println("Quarta-feira"); break; case 5: System.out.println("Quinta-feira"); break; case 6: System.out.println("Sexta-feira"); break; case 7: System.out.println("Sabado"); break; default: System.out.println("Numero invalido"); } }
public static void main(String[] args) { int intentos = 4; int numeroIntroducido; boolean acertado = false; do { System.out.print("Introduzca la clave, por favor: "); numeroIntroducido = Integer.parseInt(System.console().readLine()); if ((numeroIntroducido < 1000) || (numeroIntroducido > 9999)) { System.out.println("La clave debe ser de 4 cifras\n"); intentos--; } if (numeroIntroducido == 3289) { acertado = true; } else { System.out.println("Clave incorrecta"); } intentos--; } while ((intentos > 0) && (!acertado)); if (acertado) { System.out.println("La caja fuerte se ha abierto satisfactoriamente."); } else { System.out.println("Lo siento, esa no es la combinación."); } }
/** @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Console c; c = System.console(); // Variaveis int n = 1; int x = 0; String str_n; while (n != 0) { // Entrada str_n = c.readLine("\nDigite um numero (digite 0 para sair): "); // Conversão n = Integer.parseInt(str_n); x = n % 2; switch (x) { case 0: System.out.println("Par"); break; case 1: System.out.println("Impar"); break; default: break; } } }
public static void main(String[] argv) { Console c = System.console(); if (c == null) { System.err.println("No System Console...."); System.err.println("Use IDE Console...."); } do { String input = sc.nextLine(); if (input.equalsIgnoreCase("START") && !started) { System.out.println("Starting server ..."); appServer = new ServerApp(Config.DEFAULT_PORT); started = Boolean.TRUE; } if (input.equalsIgnoreCase("SHUTDOWN") && started) { System.out.println("Shutting server down ..."); started = Boolean.FALSE; done = Boolean.TRUE; } } while (!done); System.exit(1); }
/** * Returns a password from standard input. * * @return password */ public static String password() { // use standard input if no console if defined (such as in Eclipse) if (NOCONSOLE) return input(); // hide password final char[] pw = System.console().readPassword(); return pw != null ? new String(pw) : ""; }
public static void main(String[] args) { String signo = ""; System.out.print("Introduce un número: "); int num = Integer.parseInt(System.console().readLine()); if (num < 0) { num = num * -1; signo = "-"; } if (num < 10 && num > 0) { System.out.print("El número " + signo + num + " tiene una cifra"); } if (num >= 10 && num > 0 && num < 100) { System.out.print("El número " + signo + num + " tiene dos cifras"); } if (num >= 100 && num > 0 && num < 1000) { System.out.print("El número " + signo + num + " tiene tres cifras"); } if (num >= 1000 && num > 0 && num < 10000) { System.out.print("El número " + signo + num + " tiene cuatro cifras"); } if (num >= 10000 && num > 0 && num < 100000) { System.out.print("El número " + signo + num + " tiene cinco cifras"); } }
public static void main(String[] args) { int numero = 0; int intento = 5; int respuesta = 0; boolean adivinado = true; numero = (int) (Math.random() * 100); // numeros aleatorios del 0 al 100 System.out.println("Adivina el número, puedes poner un número del 0 al 100"); do { // mientras los intentos sean mayores a 0 (5 intentos) y no esté adivinado respuesta = Integer.parseInt(System.console().readLine()); if (respuesta < numero) { System.out.println("El número introducido es menor"); } if (respuesta > numero) { System.out.println("El número introducido es mayor"); } if (respuesta == numero) { // Se comprueba que la respuesta es = al número generado System.out.print("Has adivinado el número"); adivinado = true; } else { intento--; // si no es, se resta un intento adivinado = false; if (intento == 0) { // se comprueban si quedan intentos System.out.println("Se acabaron los intentos"); } else { System.out.println("Te quedan " + intento + " intentos, vuelve a probar"); } } } while (intento > 0 && !adivinado); System.out.println("El número era" + numero); }
public static void main(String[] args) { Console myConsole = System.console(); System.out.println("Please enter a number greater than 0!"); String stringNumber = myConsole.readLine(); Integer number = Integer.parseInt(stringNumber); ArrayList<String> allEntries = new ArrayList<String>(); for (Integer i = 1; i <= number; i++) { String currentEntry = pingPongMethod(i); allEntries.add(currentEntry); // // // if(i % 3 == 0 && i % 5 == 0) { // allEntries.add("ping-pong"); // } else if (i % 3 == 0) { // allEntries.add("ping"); // } else if (i % 5 == 0 ) { // allEntries.add("pong"); // } else { // String numbers = Integer.toString(i); // allEntries.add(numbers); // } // // // } // System.out.println(allEntries); } }
public static void main(String[] arg) { Console myConsole = System.console(); System.out.println("what is your favorite number"); String favoriteNumber = myConsole.readLine(); System.out.println("Your favorite number is " + favoriteNumber + "? Me Too!"); }