chishi's blog

By chishi, 14 years ago, In English
import java.io.*;

public class capslock
{
    public static void main(String[]args) throws IOException
    {
                
        System.out.print("Enter a word: ");
        System.out.println(setWord());
    }
    
    public static String setWord() throws IOException
    {
        BufferedReader userInput = new BufferedReader (new InputStreamReader (System.in));
        
        String word = userInput.readLine();
        word = word.toLowerCase();
        word = word.substring(0,1).toUpperCase()+word.substring(1);
        
        return word;
    }
}

Full text and comments »

  • Vote: I like it
  • -14
  • Vote: I do not like it

By chishi, 14 years ago, In English
import java.util.*;

public class permutation
{
    static Scanner userInput = new Scanner (System.in);
    
    public static void main(String[]args)
    {
        int num;
        int counter=0;
        
        //set number in the sequence
        System.out.print("Enter number in the sequence: ");
        num=userInput.nextInt();
        
        //set sequence
        int sequence[] = new int [num];
        
        System.out.print("Enter sequence(separated by spaces): ");
        
        for (int x=0; x<num; x++)
        {
            sequence[x] = userInput.nextInt();
        }
        
        //compare
        for (int y=0; y<(num-1); y++)
        {
            if (sequence[y] == sequence[y+1])
                counter++;
        }
        
        System.out.println(counter);
    
        
    }
}




   

Full text and comments »

  • Vote: I like it
  • -20
  • Vote: I do not like it

By chishi, 14 years ago, In English
import java.io.*;

public class punctuation
{
    public static void main(String[]args) throws IOException
    {
        BufferedReader userInput = new BufferedReader (new InputStreamReader(System.in));
        
        System.out.println("Enter a sentence: ");
        String sentence = userInput.readLine();
        
        for (int x=1; x<sentence.length(); x++)
        {
            if (sentence.charAt(x) == ' ')
            {
                if (sentence.charAt(x-1) == ' ')
                {    
                    sentence=removeCharAt(sentence, x-1);
                    x--;
                }
                else if (sentence.charAt(x+1) == ','||sentence.charAt(x) == '.' || sentence.charAt(x) == '!' || sentence.charAt(x) == '?')
                {
                    sentence=exchange(sentence, x-1);
                    x--;
                }
            }
            
            if (sentence.charAt(x) == ',' ||sentence.charAt(x) == '.' || sentence.charAt(x) == '!' || sentence.charAt(x) == '?')
            {
                if ((x+1) == sentence.length())
                {
                    break;
                }
                
                else if (sentence.charAt(x+1) != ' ')
                {
                    sentence=insertSpace(sentence, x+1);
                    x--;
                }
            }
        }
            System.out.println(sentence);
    }
    
    public static String removeCharAt(String s, int pos)
    {
           StringBuffer buf = new StringBuffer(s.length() - 1);
           buf.append(s.substring(0,pos)).append(s.substring(pos+1) );
           return buf.toString();
    }
    
    public static String exchange(String s, int pos)
    {
        StringBuffer sent = new StringBuffer(s.length());
        char temp= s.charAt(pos);
        sent.append(s.substring(0,pos)).append(temp).append(s.substring(pos+2));
        
        return sent.toString();
        
    }
    
    public static String insertSpace(String s, int pos)
    {
        StringBuffer buf = new StringBuffer(s.length() +1);
           buf.append(s.substring(0,pos)).append(' ').append(s.substring(pos) );
           return buf.toString();
    }

}

Full text and comments »

  • Vote: I like it
  • -21
  • Vote: I do not like it