What's new

Closed My very First System

Status
Not open for further replies.

Carly_Rose

Eternal Poster
Joined
Dec 8, 2018
Posts
1,288
Reaction
245
Points
361
thanks to Arcturus
SYSTEM INFO:

Convert to Ascii Code
Greatest Common Denominator
Least Common Multiple
Reverse Digit

Code:
public class ConverterToAsciiCode
{
    static Scanner userInput;
  
    public static void main(String [] args){
      
        userInput = new Scanner(System.in);
      
        while(true){
            try{
                System.out.println("WELCOME TO ASCII CONVERTER 1.0");
                System.out.println("1 - Convert To Ascii" +  "\n2 - Compute " +"\n3 - Calculate " +"\n4 - Reverse "+"\n5 - Exit");
                System.out.print("\n>: ");
                int choice = getMenuChoice();
                performChoice(choice);
            }catch(InputMismatchException i){
                userInput.next().charAt(0);
                System.out.println("Not Valid Try Again");
            }
        }  
    }
  
    public static int getMenuChoice(){
        int choice;
        choice = userInput.nextInt();
        return choice;
    }
  
    public static void performChoice(int choice){
        switch(choice){
            case 1: performConvert(); break;
            case 2: performCompute(); break;
            case 3: performCalculate(); break;
            case 4: performReverse(); break;
            case 5: performExit(); break;
            default: System.out.println("Not Valid Input");
        }
    }
  
    public static void performConvert(){
      
        System.out.println("Enter A Character To Covert to Ascii Code.");
        System.out.print(">: ");
      
        char ch = 'a';
        ch = userInput.next().charAt(0);
        int ascii = ch;
   
        System.out.println("The ASCII value of " + ch + " is: " + ascii +"\n");  
    }
  
    public static void performCompute(){
      
        int num3 = 0;
      
        System.out.print("Enter first number: ");
        int num1 = userInput.nextInt();
      
        System.out.print("Enter second number: ");
        int num2 = userInput.nextInt();
      
        for(int i = 1 ;i < num1 || i < num2 ; i++ ) {
            if(num1 % i == 0 && num2 % i == 0)
                num3 = i;
        }
        System.out.println("Greatest Common Denominator: "+num3);
    }
      
  
    public static void performCalculate(){
      
        System.out.println("Enter side one: ");
        int side1 = userInput.nextInt();
      
        System.out.println("Enter side two: ");
        int side2 = userInput.nextInt();
      
        System.out.println("The length of hypotenuse is: " + Math.hypot(side1, side2)+"\n");
    }
  
    public static void performReverse(){
      
        String original;
        String reverse = "";
      
        System.out.println("Enter any to reverse");
        original = userInput.next();

        int length = original.length();

        for (int i = length - 1; i >= 0; i--)
        {
            reverse = reverse + original.charAt(i);
        }

        System.out.println("Reverse of entered any input is: " + reverse);
    }

    public static void performExit(){
        System.exit(5);
    }
}
 
Last edited:
Status
Not open for further replies.

Similar threads

Back
Top