Advertisement
CyrusVerkest

Q 6.2

Oct 22nd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class SmallLarge {
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner in = new Scanner(System.in);
  8.         double highestValue = in.nextDouble();
  9.         double lowestValue = in.nextDouble();
  10.         int tries = 0;
  11.        
  12.         for (int currenttries = 0; currenttries <= 2; currenttries++)
  13.         {
  14.             double nextValue = in.nextDouble();
  15.             if (nextValue > highestValue)
  16.             {
  17.                 highestValue = nextValue;
  18.                 tries = currenttries;
  19.             }
  20.             double newValue = in.nextDouble();
  21.             if (newValue < lowestValue)
  22.             {
  23.                 newValue = lowestValue;
  24.                 tries = currenttries;
  25.             }
  26.         }
  27.         System.out.println("Biggest: " + highestValue);
  28.         System.out.println("Smallest: " + lowestValue);
  29.            
  30.     }
  31. }
  32. ----------------------------------------------------------------------------------------------------------------------------------
  33.  
  34. package evenodd;
  35.  
  36. import java.util.Scanner;
  37.  
  38. public class EvenOdd {
  39.  
  40.     public static void main(String[] args)
  41.     {
  42.         Scanner in = new Scanner(System.in);
  43.         Scanner n = new Scanner(System.in);
  44.        
  45.        
  46.        
  47.        
  48.         System.out.print("How many numbers do you want to enter?");
  49.         int numEnter = n.nextInt();
  50.         int numOdd = 0;
  51.         int numEven = 0;
  52.        
  53.         for  (int input = 1; input <= numEnter; input++)
  54.         {
  55.            
  56.            
  57.             int even = in.nextInt();
  58.             if (even %2 == 0)
  59.             {
  60.                 numEven++;
  61.             }
  62.             else
  63.             {
  64.                 numOdd++;
  65.             }
  66.            
  67.  
  68.            
  69.  
  70.            
  71.         }
  72.         int theOdd = numOdd;
  73.         int theEven = numEven;
  74.         System.out.println("odds " + theOdd);
  75.         System.out.print("evens " + theEven);
  76.  
  77.     }
  78.  
  79. }
  80. ---------------------------------------------------------------------------------------------------------------------------------
  81. public class PowersOfTwo {
  82.  
  83.     public static void main(String[] args) {
  84.        
  85.         int power = 0;
  86.         int i = 2;
  87.         while (power < 20)
  88.             {
  89.                 int n = power * power;
  90.                 int j = n * i;
  91.                
  92.                 power++;
  93.                
  94.                 System.out.println(j);
  95.                
  96.                
  97.            
  98.        
  99.             }
  100.     }
  101.  
  102. }
  103. ---------------------------------------------------------------------------------------------------------------------------------
  104. package adjacent;
  105.  
  106. import java.util.Scanner;
  107.  
  108. public class Adjacent {
  109.  
  110.     public static void main(String[] args) {
  111.         Scanner in = new Scanner(System.in);
  112.         boolean found = false;
  113.         int position = 0;
  114.         char numCh;
  115.         int numMinus;
  116.  
  117.         System.out.println("Enter some numbers");
  118.         int input = in.nextInt();
  119.        
  120.         String s = Integer.toString(input);
  121.         while(!found && position < s.length())
  122.         {
  123.            
  124.             numCh  = s.charAt(position);
  125.            
  126.             if (numCh %2 != 0  )
  127.             {
  128.                 found = true;
  129.                 System.out.print(numCh);
  130.                 continue;
  131.             }
  132.             else
  133.             {
  134.                 position++;
  135.             }      
  136.            
  137.         }
  138.        
  139.        
  140.                
  141.     }
  142.  
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement