public static LinkedList<profile> importer() throws IOException { LinkedList<profile> people = new LinkedList<profile>(); Scanner sFile; profile entry; try { sFile = new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/users.dat")); sFile.nextLine(); while (sFile.hasNext()) { String profile = sFile.nextLine(); // System.out.println(profile); Scanner profScan = new Scanner(profile); profScan.useDelimiter(","); while (profScan.hasNext()) { Long id = profScan.nextLong(); String ident = String.valueOf(id); String rot_Id = rot13.encrypt(ident); Long rot_IntId = Long.parseLong(rot_Id); String fname = profScan.next(); String rot_Name = rot13.encrypt(fname); // String sname = profScan.next(); // int age = profScan.nextInt(); String gender = profScan.next(); String nat = profScan.next(); entry = new profile(id, fname, gender, nat); // System.out.println("id: "+id+" name: "+fname+" gender: "+gender+" nationality: "+nat); // System.out.println("id: "+rot_IntId+" name: "+rot_Name+" gender: "+gender+" // nationality: "+nat); people.add(entry); } } } catch (IOException ex) { // return people; System.out.println("(No System File profile.txt)" + ex); } return people; }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); int num[][] = { {0, 2, 3, 5, 6, 7, 8, 9}, {2, 3, 4, 5, 6, 8, 9}, {0, 2, 3, 5, 6, 8, 9}, {0, 4, 5, 6, 8, 9}, {0, 1, 2, 3, 4, 7, 8, 9}, {0, 2, 6, 8}, {0, 1, 3, 4, 5, 6, 7, 8, 9} }; while (scanner.hasNextInt()) { int a = scanner.nextInt(); String b = scanner.next(); if (a == 0) break; String data[][] = new String[5 + (a - 1) * 2][(3 + (a - 1)) * b.length()]; for (int i = 0; i < 5 + (a - 1) * 2; i++) for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) data[i][j] = " "; for (int i = 0; i < b.length(); i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < num[j].length; k++) { if ((int) b.charAt(i) - 48 == num[j][k]) { for (int h = 0; h < a; h++) data[(a + 1) * j][1 + i * (a + 2) + h] = "-"; } } } for (int j = 3; j < 5; j++) { for (int k = 0; k < num[j].length; k++) { if ((int) b.charAt(i) - 48 == num[j][k]) { for (int h = 0; h < a; h++) data[1 + h][(j - 3) * (a + 1) + (i * (a + 2))] = "|"; } } } for (int j = 5; j < 7; j++) { for (int k = 0; k < num[j].length; k++) { if ((int) b.charAt(i) - 48 == num[j][k]) { for (int h = 0; h < a; h++) data[a + 2 + h][(j - 5) * (a + 1) + (i * (a + 2))] = "|"; } } } } StringBuffer sb = new StringBuffer(""); for (int i = 0; i < 5 + (a - 1) * 2; i++) { for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) { if ((j - (a + 1)) % (a + 2) == 0 && (j + 1) != (3 + (a - 1)) * b.length()) sb.append(data[i][j] + " "); else sb.append(data[i][j]); } sb.append("\n"); } System.out.println(sb); } }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); while (scanner.hasNext()) { String str = scanner.next(); if (str.equals("*")) break; if ((int) str.charAt(0) < 97) num(str); else abcd(str); } }
public static void main(String args[]) { int T; String s; Scanner in = new Scanner(System.in); T = in.nextInt(); for (int i = 0; i < T; i++) { s = in.next(); // toReverse(s); reverse(s); System.out.println(); } }
public static void main(String[] args) { Scanner scan = new Scanner(System.in); String line = System.getProperty("line.separator"); scan.useDelimiter(line); int cases = scan.nextInt(); for (int x = 0; x < cases; x++) { String[] get = scan.next().split(" "); System.out.println(Integer.parseInt(get[0]) % Integer.parseInt(get[1])); } }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (scanner.hasNext()) { String str = scanner.next(); if (str.equals("0")) break; Long sum = 0L; for (int i = str.length() - 1, j = 1; i >= 0; i--, j++) { sum = sum + ((long) Math.pow(2, j) - 1) * ((long) str.charAt(i) - 48); } System.out.println(sum); } }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int num; while ((num = scanner.nextInt()) != 0) { ArrayList<String> all = new ArrayList<String>(); for (int i = 0; i < num; i++) { all.add(scanner.next()); } Collections.sort(all, comptr); StringBuilder sb = new StringBuilder(""); for (String s : all) { sb.append(s); } System.out.println(sb); } }
public void scanFile(String filename) { int i = 0; String line = null; try { File filescan = new File(filename); ; FileReader f = new FileReader(filescan); BufferedReader fileReader = new BufferedReader(f); while ((line = fileReader.readLine()) != null) { if (i == 0) // read dimensions and create map { String[] temp = line.split(" "); row = Integer.parseInt(temp[0]); col = Integer.parseInt(temp[1]); map = new char[row][col]; line = fileReader.readLine(); } Scanner scan = new Scanner(line); String temp = scan.next(); char[] charline = temp.toCharArray(); // System.out.println(charline); map[i] = charline; i++; } } catch (FileNotFoundException e) { System.out.println("Error opening file!"); } catch (IOException ex) { System.out.println("Error reading file!"); } }
/** * Evaluates a mathematical expression and returns the result * * @param expression String * @return boolean */ public int parse(String expression) throws NoSuchElementException { Scanner scan = new Scanner(expression); Stack<Integer> stack1 = new Stack<Integer>(); int num1; int num2; while (scan.hasNext()) { try { if (scan.hasNextInt()) { int num = scan.nextInt(); stack1.push(num); // System.out.println("push "+ num); } else { // String str = scan.nextChar(); // System.out.println("scan "+ scan.next()); String str = scan.next(); if (str.equals("+")) { num1 = stack1.pop(); // System.out.println("num1 = "+ num1); num2 = stack1.pop(); // System.out.println("num1 = "+ num2); stack1.push(num1 + num2); } if (str.equals("-")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num2 - num1); } if (str.equals("/")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num2 / num1); } if (str.equals("*")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num1 * num2); } if (str.equals("%")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num2 % num1); } if (str.equals("&")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num1 & num2); } if (str.equals("^")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num1 ^ num2); } if (str.equals("|")) { num1 = stack1.pop(); num2 = stack1.pop(); stack1.push(num1 | num2); } if (str.equals("~")) { num1 = stack1.pop(); stack1.push(~num1); } } } catch (NoSuchElementException e) { System.out.println("empty stacfgdgdfgk"); } } // int result = stack1.pop(); // System.out.println(result); return stack1.pop(); }