Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- // Coding Situation 1
- String sName = "Daniel Joseph";
- String sNameRev = "";
- for(int i = 0; i<sName.length(); i++)
- {
- sNameRev +=sName.charAt(sName.length()-i-1);
- }
- JOptionPane.showMessageDialog(null, sNameRev);
- // Coding Situation 2
- char cChar = 'A';
- String sType = "";
- if(cChar == 'A' || cChar == 'E' || cChar == 'I' || cChar == 'O' || cChar == 'U')
- {
- sType = "It's a Vowel";
- }
- else
- {
- sType = "It's a Consonant";
- }
- JOptionPane.showMessageDialog(null, sType);
- //Coding Situation 3
- char cChar2 = 'A';
- String sType2 = "";
- switch (cChar2)
- {
- case 'A':
- case 'E':
- case 'I':
- case 'O':
- case 'U':
- sType2 = "It's a Vowel";
- break;
- default:
- sType2 = "It's a Consenant";
- }
- JOptionPane.showMessageDialog(null, sType2);
- // Coding Situation 4
- int iSum = 0;
- int iEvenNums = 2;
- do
- {
- iSum+=iEvenNums;
- iEvenNums+=2;
- }while(iSum != 110);
- System.out.println(iSum);
- //Coding Situation 5
- int iTownAPop = 5000;
- int iTownBPop = 8000;
- int iYearCount = 0;
- while(iTownAPop < iTownBPop)
- {
- iTownAPop *= (1 + 0.04);
- iTownBPop *= (1 + 0.02);
- iYearCount++;
- //System.out.println(iTownAPop + "\n" + iTownBPop + "\n" + iYearCount );
- }
- System.out.println(iYearCount );
- //Coding Situation 6
- DecimalFormat dfFormat = new DecimalFormat("000");
- for(int iNumber1 = 1; iNumber1<=9; iNumber1+=2)
- {
- for(int iNumber2 = 1; iNumber2 <= 9; iNumber2+=2)
- {
- System.out.print(dfFormat.format(iNumber1 * iNumber2) + " " );
- }
- System.out.println();
- }
- //Coding Situation 7
- String sPhone = "";
- boolean bValid = true;
- sPhone = JOptionPane.showInputDialog("Phone Number such as 413-555-1212 ");
- // --> Put your logic here
- bValid = sPhone.length() == 12 && sPhone.startsWith("413") && sPhone.startsWith("555", 4)
- && sPhone.startsWith("-", 3) && sPhone.startsWith("-", 7);
- for(int i = 0; i<4; i++)
- {
- if(!Character.isDigit(sPhone.charAt(sPhone.length()-i-1)))
- {
- bValid = false;
- }
- }
- JOptionPane.showMessageDialog(null, sPhone + " is valid: " + bValid,
- "Coding Question 7", JOptionPane.INFORMATION_MESSAGE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement