Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.52 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         // TODO Auto-generated method stub
  4.         System.out.print("Hello Brighton");
  5. }
  6. }
  7. public class Main
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         double mark;       
  12.         System.out.println("#Input cw");
  13.         int cw = BIO.getInt();
  14.         System.out.println("#Input ex");
  15.         int ex = BIO.getInt();
  16.         mark = (cw + ex) / 2.0;
  17.         System.out.printf("ex = %d cw = %d mark = %.1f  \n", ex, cw, mark);
  18.     }
  19. }
  20. public class Main extends BIO
  21. {
  22.     public static void main(String[] args)
  23.     {
  24.         double mark;
  25.         System.out.println("#Input Student Number");
  26.         int sn = BIO.getInt();
  27.              while (sn > 0)
  28.             {
  29.                 System.out.println("#Input ex");
  30.                 int ex = BIO.getInt();
  31.                 System.out.println("#Input cw");
  32.                 int cw = BIO.getInt();
  33.                 mark = (ex + cw) / 2.0;
  34.                 System.out.printf("sn = %d ex = %d cw = %d mark = %.1f \n", sn, cw, ex, mark);
  35.                 System.out.println("#Input Student Number");
  36.                 sn = BIO.getInt();
  37.             }            
  38.            }    
  39.       }      
  40. public class Main
  41. {
  42.     public static void main(String[] args)
  43.     {
  44.         System.out.print("#Enter size of square: ");
  45.         int size = BIO.getInt();
  46.         int line = 1;
  47.         while (line <= size)
  48.         {
  49.             int stars = 1;
  50.             while (stars <= size)
  51.             {
  52.                 System.out.print("*");
  53.                 stars++;
  54.             }
  55.             System.out.println();
  56.             line++;
  57.        }
  58.    }
  59. }
  60.      class Main
  61.  {
  62.      public static void main (String args[])
  63.      {
  64.          System.out.println("#Input square size: ");
  65.          int size = BIO.getInt();
  66.          for (int row=1; row<=size; row++)
  67.          {
  68.              for(int col=1; col<=size; col++)
  69.              {
  70.                  if (row==1 || row==size || col==1 || col==size)
  71.                  {
  72.                      System.out.printf("*");
  73.                     }
  74.                     else
  75.                     {
  76.                         System.out.printf(".");
  77.                     }
  78.                 }
  79.             System.out.println();
  80.         }
  81.     }
  82. }
  83.  class Main
  84.  {
  85.      public static void main (String args[])
  86.      {
  87.     System.out.print("#Please enter you name: ");
  88.         String name = BIO.getString();        
  89.             while (!name.equals("END"))
  90.                  {                      
  91.                  System.out.print("#Please enter your module mark: ");
  92.                  int mark = BIO.getInt();
  93.                  
  94.                  if (mark >= 40)
  95.                  {
  96.                      String result = ("Pass");
  97.                      System.out.printf("%s %s\n", name , result);
  98.                     }
  99.                     else
  100.                     {
  101.                      String result = ("Fail");
  102.                      System.out.printf("%s %s\n", name, result);
  103.                     }
  104.             System.out.print("#Please enter you name: ");
  105.             name = BIO.getString();
  106.  
  107.                 }            
  108.            }    
  109.       }      
  110. class Main
  111.  {
  112.      public static void main (String args[])
  113.      {
  114.     String name, result;
  115.     int mark;
  116.     System.out.print("#Please enter you name: ");
  117.         name = BIO.getString();
  118.          
  119.             while (!name.equals("END"))
  120.                  {
  121.                  System.out.print("#Please enter your module mark: ");
  122.                  mark = BIO.getInt();
  123.                  if (mark >= 70)
  124.                  {
  125.                     result = "gains a 1st";
  126.                     }
  127.                     else if (mark < 70 && mark >= 60)
  128.                     {
  129.                   result = "gains a 2.1";
  130.                     }
  131.                    else if (mark < 60 && mark >= 50)
  132.                     {
  133.                result = "gains a 2.2";
  134.                     }
  135.                    else if (mark < 50 && mark >= 40)
  136.                     {
  137.                  result = "gains a 3rd";
  138.                     }
  139.                    else
  140.                     {
  141.                     result = "fails";
  142.                     }
  143.              System.out.printf("%s [%d] %s\n", name, mark, result);
  144.              System.out.print("#Please enter you name: ");
  145.             name = BIO.getString();
  146.                 }            
  147.            }    
  148.       }      
  149.  public class Main
  150.  {
  151.      public static void main (String args[])
  152.      {
  153.          String name;
  154.          int cmark;
  155.          int emark;
  156.          double omark;        
  157.          System.out.print("#Please enter you name: ");
  158.          name = BIO.getString();        
  159.             while (!name.equals("END"))
  160.             {                              
  161.                  System.out.print("#Please enter your coursework mark: ");
  162.                  cmark = BIO.getInt();                
  163.                  System.out.print("#Please enter your exam mark: ");
  164.                  emark = BIO.getInt();                
  165.                  omark = (cmark + emark) / 2.0;
  166.                  String result;
  167.                     if (omark >= 40 && cmark >= 30 && emark >= 30)
  168.                     {
  169.                      result = "Pass";
  170.                 System.out.printf("%s [%d , %d] %.1f %s\n", name, cmark, emark, omark, result);
  171.                     }    
  172.                     else if (omark < 40)
  173.                     {
  174.                      result = "Fail";
  175.                 System.out.printf("%s [%d , %d] %.1f %s\n", name, cmark, emark, omark, result);
  176.                     }                    
  177.                     else if (omark >= 40 && cmark >= 30 || emark >= 30)
  178.                     {
  179.                     result = "Fail [Threshold]";    
  180.                 System.out.printf("%s [%d , %d] %.1f %s\n", name, cmark, emark, omark, result);
  181.                     }
  182.                 System.out.print("#Please enter your name: ");
  183.                 name = BIO.getString();
  184.             }            
  185.        }    
  186.  }                        
  187. class Main extends BIO {
  188.   public static void main (String args[]) {
  189.     System.out.println("#Please enter size of diamond: ");
  190.     int sod = BIO.getInt();
  191.     int middle;
  192.     int count;        
  193.     if (sod % 2 != 0 && sod > 4 && sod < 42) {    
  194.      middle = sod/2;        
  195.      //line 1
  196.      for(int i = 0; i < middle; i++){
  197.       System.out.print(".");
  198.       }
  199.      System.out.print("*");
  200.      for (int i = 0; i < middle; i++){
  201.       System.out.print(".");
  202.      }
  203.      System.out.println();
  204.  //1.st middle part
  205.      for(int row = 1; row < middle+1; row++){
  206.       for (int i = 0; i < (middle-row); i++){
  207.        System.out.print(".");
  208.       }
  209.       System.out.print("*");
  210.       for (int i = 0; i < (row*2-1); i++){
  211.        System.out.print(".");
  212.       }
  213.       System.out.print("*");
  214.       for (int i = 0; i < (middle-row); i++){
  215.        System.out.print(".");
  216.       }
  217.       System.out.println();
  218.      }    
  219.      //2.nd middle      
  220.      count = sod - 4;
  221.      for(int row=1;row<middle;row++){
  222.       for (int i = 0; i < row; i++){
  223.        System.out.print(".");
  224.       }
  225.       System.out.print("*");
  226.       for(int i = 0; i<count; i++){
  227.        System.out.print(".");
  228.       }
  229.       count = count - 2;
  230.       System.out.print("*");
  231.       for (int i = 0; i < row; i++){
  232.        System.out.print(".");
  233.        }
  234.        System.out.println();
  235.       }
  236.     // last line  
  237.      for(int i = 0; i < middle; i++){
  238.       System.out.print(".");
  239.      }
  240.     System.out.print("*");
  241.      for (int i = 0; i < middle; i++){
  242.       System.out.print(".");
  243.      }
  244.      System.out.println();
  245.     }    
  246.      else if (sod < 5 || sod > 41){
  247.      System.out.println("Side of diamond " + "(" + sod + ")" + " must be between 5 & 41");
  248.      }
  249.      else {
  250.      System.out.println("Side of diamond " + "(" + sod + ")" + " must be odd");
  251.      }
  252.   }
  253.  }
  254. class Main extends BIO {
  255.   public static void main(String args[]) {
  256.    System.out.println("Amount Coins");
  257.    System.out.print("#Enter amount: ");
  258.    int input = BIO.getInt();
  259.    while (input != 0) {
  260.     int amount = input;
  261.     if (input >= 1 && input <= 500) {
  262.      //calculate 200ps
  263.      int i200 = input / 200;
  264.      int a200 = 0;
  265.      while (i200 >= 1) {
  266.       a200++;
  267.       input = input - 200;
  268.       i200 = (input / 200);
  269.      }
  270.      //calculate 100ps
  271.      int i100 = input / 100;
  272.      int a100 = 0;
  273.      while (i100 >= 1) {
  274.       a100++;
  275.       input = input - 100;
  276.       i100 = (input / 100);
  277.      }
  278.  
  279.      //calculate 50ps
  280.      int i50 = input / 50;
  281.      int a50 = 0;
  282.      while (i50 >= 1) {
  283.       a50++;
  284.       input = input - 50;
  285.       i50 = (input / 50);
  286.      }
  287.      //calculate 20ps
  288.      int i20 = input / 20;
  289.      int a20 = 0;
  290.      while (i20 >= 1) {
  291.       a20++;
  292.       input = input - 20;
  293.       i20 = (input / 20);
  294.      }
  295.      //ccalculate 10ps
  296.      int i10 = input / 10;
  297.      int a10 = 0;
  298.      while (i10 >= 1) {
  299.       a10++;
  300.       input = input - 10;
  301.       i10 = (input / 10);
  302.      }
  303.      //calculate 5ps
  304.      //int input = 20;                    
  305.      int i5 = input / 5; //(=4)
  306.      int a5 = 0;
  307.      while (i5 >= 1) {
  308.       a5++; //n5 = 0 is now n5 = 1
  309.       input = input - 5; //20 - 5 -> input = 15 (5p taken away)
  310.       i5 = (input / 5); //i5 = 15 / 5 -> i5 = 3
  311.      }
  312.      //calculate 2ps
  313.      int i2 = input / 2;
  314.      int a2 = 0;
  315.      while (i2 >= 1) {
  316.       a2++;
  317.       input = input - 2;
  318.       i2 = (input / 2);
  319.      }
  320.      //calculate 1ps
  321.      int i1 = input / 1;
  322.      int a1 = 0;
  323.      while (i1 >= 1) {
  324.       a1++;
  325.       input = input - 1;
  326.       i1 = (input / 1);
  327.      }
  328.      int sum = a200 + a100 + a50 + a20 + a10 + a5 + a2 + a1;
  329.      //output
  330.      System.out.print(amount + "p ");
  331.      if (sum == 1) {
  332.       System.out.print(sum + " coin");
  333.      } else {
  334.       System.out.print(sum + " coins");
  335.      }
  336.      // 200p
  337.      if (a200 == 0) {
  338.       System.out.print(" ");
  339.      }
  340.      if (a200 == 1) {
  341.       System.out.print(" 200p ");
  342.      }
  343.      if (a200 > 1) {
  344.       System.out.printf(" %d*200p ", a200);
  345.      }
  346.      // 100p
  347.      if (a100 == 0) {
  348.       System.out.print(" ");
  349.      }
  350.      if (a100 == 1) {
  351.       System.out.print(" 100p ");
  352.      }
  353.      if (a100 > 1) {
  354.       System.out.printf(" %d*100p ", a100);
  355.      }
  356.      // 50p
  357.      if (a50 == 0) {
  358.       System.out.print(" ");
  359.      }
  360.      if (a50 == 1) {
  361.       System.out.print(" 50p ");
  362.      }
  363.      if (a50 > 1) {
  364.       System.out.printf(" %d*50p ", a50);
  365.      }
  366.      // 20p
  367.      if (a20 == 0) {
  368.       System.out.print(" ");
  369.      }
  370.      if (a20 == 1) {
  371.       System.out.print(" 20p ");
  372.      }
  373.      if (a20 > 1) {
  374.       System.out.printf(" %d*20p ", a20);
  375.      }
  376.      // 10p
  377.      if (a10 == 0) {
  378.       System.out.print(" ");
  379.      }
  380.      if (a10 == 1) {
  381.       System.out.print(" 10p ");
  382.      }
  383.      if (a10 > 1) {
  384.       System.out.printf(" %d*10p ", a10);
  385.      }
  386.      // 5p
  387.      if (a5 == 0) {
  388.       System.out.print(" ");
  389.      }
  390.      if (a5 == 1) {
  391.       System.out.print(" 5p ");
  392.      }
  393.      if (a5 > 1) {
  394.       System.out.printf(" %d*5p ", a5);
  395.      }
  396.      // 2p
  397.      if (a2 == 0) {
  398.       System.out.print(" ");
  399.      }
  400.      if (a2 == 1) {
  401.       System.out.print(" 2p ");
  402.      }
  403.      if (a2 > 1) {
  404.       System.out.printf(" %d*2p ", a2);
  405.      }
  406.      // 1p
  407.      if (a1 == 0) {
  408.       System.out.print(" ");
  409.      }
  410.      if (a1 == 1) {
  411.       System.out.print(" 1p ");
  412.      }
  413.      if (a1 > 1) {
  414.       System.out.printf(" %d*1p ", a1);
  415.      }
  416.     } else {
  417.      System.out.println("Invalid amount " + amount + "p");
  418.     }
  419.     input = BIO.getInt();
  420.    }
  421.   }
  422.  }
  423. class Main extends BIO {
  424.     public static void main(String args[]) {
  425.         System.out.println("#Enter a line of text: ");
  426.         String text = BIO.getString();
  427.         int spaces;
  428.         while (! text.equals("END")) {
  429.             char[] textchars = text.toCharArray();
  430.             int count = 0;
  431.             for (int i=0; i<textchars.length; i++) {
  432.                 if (textchars[i] == ' ') {
  433.                     count++;
  434.                 }
  435.             }
  436.            
  437.             //System.out.println("["+count+"]");
  438.             //System.out.printf("[%d] %s %s", count, " spaces in ", \"",text,"\");  
  439.             System.out.println("["+count+"]" + " spaces in " + "\"" + text + "\"");
  440.             text = BIO.getString();
  441.         }
  442.     }
  443. }
  444.  
  445. class Main extends BIO {
  446.     public static void main(String args[]) {
  447.     System.out.println("#Enter any word: ");
  448.     String text = BIO.getString();
  449.     int vowels;
  450.     while (! text.equals("END")) {
  451.         char[] textchars = text.toCharArray();
  452.         int count = 0;
  453.         for (int i=0; i<textchars.length; i++) {
  454.             if (textchars[i] == 'a' || textchars[i] == 'A' || textchars[i] == 'e' || textchars[i] == 'E' || textchars[i] == 'i' || textchars[i] == 'I' || textchars[i] == 'o' || textchars[i] == 'O' || textchars[i] == 'u' || textchars[i] == 'U') {
  455.                 count++;
  456.             }
  457.         }
  458.         System.out.println("[" + count + "]" + " vowels in " + "\"" + text + "\"");
  459.         text = BIO.getString();
  460.         }
  461.     }
  462. }
  463. class Main extends BIO {
  464.   public static void main (String[] args) {
  465.      System.out.println("#Enter 1 word: ");
  466.      String word = BIO.getString();
  467.     while (! word.equals("END")) {
  468.       String wordlower = word.toLowerCase();
  469.       int length = word.length();
  470.       boolean ascend = true;
  471.       int j=0;
  472.      for (int i=0; i<length - 1; i++){
  473.         j = i+1;
  474.         if (wordlower.charAt(i) > wordlower.charAt(j)) {
  475.           ascend = false;
  476.         }
  477.      }
  478.      if (ascend){
  479.       System.out.println(word + " letters in ascending order");
  480.      }
  481.      else {
  482.       System.out.println(word + " letters not in ascending order");
  483.      }
  484.      System.out.println("#Enter another word: ");
  485.      word = BIO.getString();  
  486.     }
  487.   }
  488. }
  489.  
  490.  
  491. class Main extends BIO {
  492.   public static void main (String[] args) {
  493.      System.out.println("#Enter 1 word: ");
  494.      String word = BIO.getString();
  495.     while (! word.equals("END")) {
  496.       String wordlower = word.toLowerCase();
  497.       int length = word.length();
  498.       int half = length / 2;
  499.       boolean palindrome = true;
  500.  
  501.       for (int i=0, j=length -1; i<length/2; i++, j--){
  502.          if (wordlower.charAt(i) != wordlower.charAt(j)) {
  503.            palindrome = false;
  504.          }
  505.          
  506.       }
  507.       if (palindrome){
  508.        System.out.println(word + " is a palindrome");
  509.       }
  510.       else {
  511.        System.out.println(word + " is not a palindrome");
  512.       }
  513.       System.out.println("#Enter another word: ");
  514.       word = BIO.getString();  
  515.     }
  516.   }
  517. }
  518. class Main extends BIO {
  519.    
  520. public static void main(String args[]) {
  521.          System.out.print("#Enter line(s) of text: ");
  522.          String s1=BIO.getString();
  523.          StringBuffer buffer=new StringBuffer();
  524.          int length=s1.length();
  525.          System.out.print("#Enter max line length: ");
  526.          int thrshld=BIO.getInt(); //this valueis threshold , which you can use
  527.          int a=length/thrshld;
  528.  
  529.          if (a<=1) {
  530.              System.out.println(s1);
  531.          }else{
  532.             String split[]=s1.split(" ");
  533.             for (int j = 0; j < split.length; j++) {
  534.                 buffer.append(split[j]+" ");
  535.  
  536.                 if (buffer.length()>=thrshld) {
  537.  
  538.                     int lastindex=buffer.lastIndexOf(" ");
  539.  
  540.                     if (lastindex<buffer.length()) {
  541.  
  542.                         buffer.subSequence(lastindex, buffer.length()-1);
  543.                         System.out.println(buffer.toString().replace(' ', '.'));
  544.                         buffer=null;
  545.                         buffer=new StringBuffer();
  546.                     }
  547.                 }
  548.             }
  549.          }
  550.      }
  551.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement