Advertisement
Camocc_Studios

WhileLoopPractice

Feb 24th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class WhileLoopsPractice {
  4.     public static void main(String[] args) {
  5.         float a = Float.parseFloat(JOptionPane.showInputDialog("Type a number to get the sqrt (negative number to exit)"));
  6.         while(a >= 0) {
  7.             JOptionPane.showMessageDialog(null, Math.sqrt(a));
  8.             a = Float.parseFloat(JOptionPane.showInputDialog("Type a number to get the sqrt (negative number to exit)"));
  9.  
  10.         }
  11.        
  12.         char b = (JOptionPane.showInputDialog("Enter a letter to check if its a vowel (# to exit)")).charAt(0);
  13.         while(b != '#') {
  14.             if(b=='a'||b=='e'|b=='i'||b=='o'||b=='u')
  15.                 JOptionPane.showMessageDialog(null,b+ " is a vowel");
  16.             else
  17.                 JOptionPane.showMessageDialog(null,b+" is not a vowel");
  18.             b = (JOptionPane.showInputDialog("Enter a letter to check if its a vowel (# to exit)")).charAt(0);
  19.  
  20.         }
  21.        
  22.         int c = Integer.parseInt(JOptionPane.showInputDialog("Enter a letter to check if its a vowel (# to exit)"));
  23.         while(c <= 255 && c >=0) {
  24.             JOptionPane.showMessageDialog(null,(int)c);
  25.             c = Integer.parseInt(JOptionPane.showInputDialog("Enter a letter to check if its a vowel (# to exit)"));
  26.         }
  27.     }
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement