本文共 6061 字,大约阅读时间需要 20 分钟。
public class book { public static void main(String[] args) { if(args.length!=3){ System.out.println("fuck you~~"); System.exit(1); } int result = 0; try{ int opt1 = Integer.parseInt(args[0]); } catch (NumberFormatException ex) { System.out.print("Wrong input: "+args[0]); } try{ int opt2 = Integer.parseInt(args[2]); } catch (NumberFormatException ex) { System.out.print("Wrong input: "+args[2]); } }}
import java.util.*;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter two integers: "); boolean in1 = true; boolean in2 = true; int jojo = 0; int dio = 0; while(in1){ try{ jojo=input.nextInt(); in1 = false; } catch (InputMismatchException jj){ input.nextLine(); System.out.print("Please enter an integer; "); } } while(in2){ try{ dio=input.nextInt(); in2 = false; } catch (InputMismatchException jj){ input.nextLine(); System.out.print("Please enter an integer; "); } } int sum=jojo+dio; System.out.print("The sum is "+sum); }}
import java.util.*;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[] ass = new int[100]; for(int i=0;i<100;i++) ass[i]=(int)(Math.random()*100); System.out.print("Enter your index: "); int index = input.nextInt(); try{ int jj = ass[index]; } catch (ArrayIndexOutOfBoundsException k){ System.out.println("Out of Bounds!"); System.exit(1); } System.out.println("The number of the index is "+ass[index]); }}
👨
public class book { public static void main(String[] args) { try{ Triangle ass = new Triangle(1,1,4); }catch(IllegalTriangleException jj){ System.out.println("You smart ass!"); System.out.println(jj); System.exit(1); } }}class IllegalTriangleException extends Exception{ private double s1; private double s2; private double s3; public IllegalTriangleException(double aa, double bb, double cc){ super("Invalid sides "+aa+" "+bb+" "+cc); s1=aa; s2=bb; s3=cc; }}class Triangle{ private double s1; private double s2; private double s3; public Triangle(double aa,double bb,double cc) throws IllegalTriangleException { if(aa
import java.util.*;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a hex-string: "); String jojo = input.next(); try{ int dio = hexToDecimal(jojo); System.out.print(dio); }catch (NumberFormatException starplatium){ System.out.print(starplatium); System.exit(1); } } public static int hexToDecimal (String hex) throws NumberFormatException{ int decimalValue = 0; hex=hex.toUpperCase(); for(int i=0;i='A'&&hexChar<='F')||(hexChar>='0'&&hexChar<='9')){ decimalValue=decimalValue*16+hexCharToDecimal(hexChar); } else{ throw new NumberFormatException("Not a hexstring!"); } } return decimalValue; } public static int hexCharToDecimal(char ch){ if(ch>='A'&&ch<='F') return 10+ch-'A'; else return ch-'0'; }}
import java.util.*;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a bin-string: "); String jojo = input.next(); try{ int dio = binToDecimal(jojo); System.out.print(dio); }catch (NumberFormatException starplatium){ System.out.print(starplatium); System.exit(1); } } public static int binToDecimal (String hex) throws BinaryFormatException{ int decimalValue = 0; for(int i=0;i
import java.util.*;public class book { public static void main(String[] args) { ArrayListh = new ArrayList (); double i = 114514; while(true){ i++; try{ h.add(i); } catch(OutOfMemoryError killerQueen){ System.out.print("Ohhhhhh!"); System.exit(1); } } }}
import java.util.*;import java.io.*;public class book { public static void main(String[] args) throws Exception { if(args.length!=2){ System.out.println("Usage: damn fool!"); System.exit(1); } File src = new File(args[1]); StringBuilder tmp= new StringBuilder(); if(!src.exists()){ System.out.println("src does not exist!"); System.exit(2); } try(Scanner input = new Scanner(src);) { while(input.hasNext()){ String jj = input.nextLine(); tmp.append(jj.replaceAll(args[0], "")+'\n'); } } src.delete(); File dst = new File(args[1]); try(PrintWriter output = new PrintWriter(dst);) { output.print(tmp); } }}
转载地址:http://vuwai.baihongyu.com/