Take a char input from the Scanner

前端 未结 22 2645
[愿得一人]
[愿得一人] 2020-11-22 05:16

I am trying to find a way to take a char input from the keyboard.

I tried using:

Scanner reader = new Scanner(System.in);
char c = reade         


        
22条回答
  •  日久生厌
    2020-11-22 05:53

    To find the index of a character in a given sting, you can use this code:

    package stringmethodindexof;
    
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    
    /**
     *
     * @author ASUS//VERY VERY IMPORTANT
     */
    public class StringMethodIndexOf {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            String email;
            String any;
            //char any;
    
    //any=JOptionPane.showInputDialog(null,"Enter any character or string to find out its INDEX NUMBER").charAt(0);       
    //THE AVOBE LINE IS FOR CHARACTER INPUT LOL
    //System.out.println("Enter any character or string to find out its INDEX NUMBER");
           //Scanner r=new Scanner(System.in);
          // any=r.nextChar();
            email = JOptionPane.showInputDialog(null,"Enter any string or anything you want:");
             any=JOptionPane.showInputDialog(null,"Enter any character or string to find out its INDEX NUMBER");
            int result;
            result=email.indexOf(any);
            JOptionPane.showMessageDialog(null, result);
    
        }
    
    }
    

提交回复
热议问题