example: // I will enter my name: Jackie Chan, on the cmd(DOS)itself, and then the program will count off the string/letters being entered.
***so it will tell that "there are 10 letters on the string"
//after that, it will count off automatically of the string/value of having the same letters.
***so it will conclude:
J-1
a-2
c-2
k-1
i-1
e-1
h-1
n-1
//after that, it will declare the letter that has the many letters having the same letter.
***so for example, on my given input string,
it will declare that letter a and c has the letters of having many samelike letters.(get's)
// Sorry for my kinda lil bit wrong grammar.
******PLEASE DO HELP ME, AND ELABORATE/EXPLAIN TO ME WELL, HOW DOES IT CYCLES,WORK,AND GOES OF THAT CODE PLEASE!!! I will do appreciate who would help me solve my problem.
Please do help me make a JAVA source code(program) that can input a string/value in the cmd(DOS)itself.?
Assuming you don't have to worry about internationalization, or funny characters, the character counting part can look like this:
============================
int charmap[], counts[];
charmap = new int[256];
// charmap is a map of character
// value to string position where it
// was first encountered
counts = new int[s.length()];
for (int i=0; i%26lt;s.length(); ++i) {
char c = s.charAt(i);
if (charmap[c] == 0) charmap[c] = i+1;
counts[charmap[c]-1]++;
}
for (int i=0; i%26lt;counts.length; ++i)
if (counts[i] != 0) System.out.println("" + s.charAt(i) + " - " + counts[i]);
}
=============================
When I run that with the string "s" set to "Jackie Chan", here is the output:
J - 1
a - 2
c - 1
k - 1
i - 1
e - 1
- 1
C - 1
h - 1
n - 1
(Note that 'c' and 'C' are counted separately, and space is also counted. If you want to count all characteres as lowercase or uppercase, convert the case of the string in front of this code. If you want to ignore spaces, add a condition to the final if statement to not print if s.charAt(1) = ' '.)
Reply:public class Main {
public static void main(String[] args) {
System.out.println(args[0]);
}
}
Save this in a file called "Main.java" and compile it using 'javac Main.java'
Now run it by the command java Main "Jackie Chan"
It will print the name.
I'm sure you can do the rest of the operations on the string yourself. you can access the string by args[0].
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment