Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.  
  3.  
  4.        
  5.         // Coding Situation 1
  6.         String sName = "Daniel Joseph";
  7.         String sNameRev = "";
  8.         for(int i = 0; i<sName.length(); i++)
  9.         {
  10.             sNameRev +=sName.charAt(sName.length()-i-1);
  11.         }
  12.         JOptionPane.showMessageDialog(null, sNameRev);
  13.        
  14.         // Coding Situation 2
  15.         char cChar = 'A';
  16.         String sType = "";
  17.        
  18.         if(cChar == 'A' || cChar == 'E' || cChar == 'I' || cChar == 'O' || cChar == 'U')
  19.         {
  20.             sType = "It's a Vowel";
  21.         }
  22.         else
  23.         {
  24.             sType = "It's a Consonant";
  25.         }
  26.         JOptionPane.showMessageDialog(null, sType);
  27.        
  28.         //Coding Situation 3
  29.         char cChar2 = 'A';
  30.         String sType2 = "";
  31.  
  32.         switch (cChar2)
  33.         {
  34.         case 'A':
  35.         case 'E':
  36.         case 'I':
  37.         case 'O':
  38.         case 'U':
  39.             sType2 = "It's a Vowel";
  40.             break;
  41.         default:
  42.             sType2 = "It's a Consenant";
  43.        
  44.    
  45.  
  46.         }
  47.         JOptionPane.showMessageDialog(null, sType2);
  48.      
  49.         // Coding Situation 4
  50.         int iSum = 0;
  51.         int iEvenNums = 2;
  52.         do
  53.         {
  54.            
  55.             iSum+=iEvenNums;
  56.             iEvenNums+=2;
  57.            
  58.         }while(iSum != 110);
  59.         System.out.println(iSum);
  60.        
  61.         //Coding Situation 5
  62.         int iTownAPop = 5000;
  63.         int iTownBPop = 8000;
  64.         int iYearCount = 0;
  65.        
  66.         while(iTownAPop < iTownBPop)
  67.         {
  68.             iTownAPop *= (1 + 0.04);
  69.             iTownBPop *= (1 + 0.02);
  70.             iYearCount++;
  71.             //System.out.println(iTownAPop + "\n" + iTownBPop + "\n" + iYearCount );
  72.         }
  73.         System.out.println(iYearCount );
  74.        
  75.         //Coding Situation 6
  76.         DecimalFormat dfFormat = new DecimalFormat("000");
  77.         for(int iNumber1 = 1; iNumber1<=9; iNumber1+=2)
  78.         {
  79.             for(int iNumber2 = 1; iNumber2 <= 9; iNumber2+=2)
  80.             {
  81.                 System.out.print(dfFormat.format(iNumber1 * iNumber2) + " " );
  82.             }
  83.             System.out.println();
  84.         }
  85.        
  86.         //Coding Situation 7
  87.         String sPhone = "";
  88.         boolean bValid = true;
  89.  
  90.         sPhone = JOptionPane.showInputDialog("Phone Number such as 413-555-1212 ");
  91.  
  92.         // --> Put your logic here
  93.         bValid = sPhone.length() == 12 && sPhone.startsWith("413") && sPhone.startsWith("555", 4)
  94.                 && sPhone.startsWith("-", 3) && sPhone.startsWith("-", 7);
  95.         for(int i = 0; i<4; i++)
  96.         {
  97.             if(!Character.isDigit(sPhone.charAt(sPhone.length()-i-1)))
  98.             {
  99.                 bValid = false;
  100.             }
  101.         }
  102.        
  103.        
  104.  
  105.         JOptionPane.showMessageDialog(null, sPhone + " is valid: " + bValid,
  106.                 "Coding Question 7", JOptionPane.INFORMATION_MESSAGE);
  107.        
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement