0% found this document useful (0 votes)
5 views1 page

Programs

The document contains three Java programs: one that counts the occurrences of characters in a given name, another that generates the first 20 numbers of the Fibonacci series, and a third that calculates the factorial of a given number (5). Each program is encapsulated within its own main method. The code demonstrates basic programming concepts such as loops, arrays, and maps.

Uploaded by

oasis.karthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Programs

The document contains three Java programs: one that counts the occurrences of characters in a given name, another that generates the first 20 numbers of the Fibonacci series, and a third that calculates the factorial of a given number (5). Each program is encapsulated within its own main method. The code demonstrates basic programming concepts such as loops, arrays, and maps.

Uploaded by

oasis.karthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

public static void main(String[] args) {

String name = "Kartheek"; // Replace "YourName" with your actual name

Map<Character, Integer> charCounts = new LinkedHashMap<>();

for (char c : name.toCharArray()) {


charCounts.put(c, charCounts.getOrDefault(c, 0) + 1);
}

System.out.println("Character counts in your name:");


for (Map.Entry<Character, Integer> entry : charCounts.entrySet()) {
System.out.println("'" + entry.getKey() + "': " +
entry.getValue());
}
}

public static void main(String[] args) {

//Fibonacci series
int[] series = new int[20];
series[0] = 0;
series[1] = 1;

for(int i=2; i< series.length; i++) {


series[i] = series[i-1] + series[i-2];
}

System.out.println(Arrays.toString(series));
}

public static void main(String[] args) {

// find factorial of a given number


int f = 5;
int facto = 1;
for (int i = f; i > 0; i--) {
facto = facto * i;
}
System.out.println(facto);
}

You might also like