Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Printing the first three characters!

$
0
0
The Question is : Write a program called "MissingChar.java". The program should read a string from the keyboard and prints the same string, with its fourth character removed. Your program must handle strings with length, greater than, less than, and equal to 4.
If the string is less than 4, then print as it is, otherwise remove the 4th character and print the string.


public class MissingChar {

    public static void main(String[] args) {

        Scanner read = new Scanner(System.in);
        System.out.print("Enter a String: ");
        String input = read.next();
        if (input.length() < 4) {
            System.out.println(input);
        } else {
            System.out.println();
        }

    }
}



how should I print only the first three characters !!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>