Calculate Average of Numbers Entered by User: Qus:-Write A Program
Calculate Average of Numbers Entered by User: Qus:-Write A Program
Calculate Average of Numbers Entered by User: Qus:-Write A Program
entered by user
import java.util.Scanner;
public class JavaExample {
Output:-
How many numbers you want to enter?
5
Enter Element No.1: 12.7
Enter Element No.2: 18.9
Enter Element No.3: 20
Enter Element No.4: 13.923
Enter Element No.5: 15.6
The average is: 16.225
Qus: Write A program Program to reverse a string entered by
user
import java.util.Scanner;
public class JavaExample {
OUTPUT:-
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
//Create a HashMap
Map<Character, Integer> map = new HashMap<Character, Integer>();
System.out.println("\nString: ChaitanyaSingh");
System.out.println("-------------------------");
obj.countDupChars("ChaitanyaSingh");
System.out.println("\nString: #@$@!#$%!!%@");
System.out.println("-------------------------");
obj.countDupChars("#@$@!#$%!!%@");
}
}
Output:-
String: BeginnersBook.com
-------------------------
Char e 2
Char B 2
Char n 2
Char o 3
String: ChaitanyaSingh
-------------------------
Char a 3
Char n 2
Char h 2
Char i 2
String: #@$@!#$%!!%@
-------------------------
Char # 2
Char ! 3
Char @ 3
Char $ 2
Char % 2
Qus:-write a Java
Program to find GCD of two numbers
using for loop
public class GCDExample1 {
//Lets take two numbers 55 and 121 and find their GCD
int num1 = 55, num2 = 121, gcd = 1;
package Applet;
import java.applet.*;
import java.awt.*;
}
}
Output:-
Qus:- Write a Java program to draw a
rectangle using swing
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;
class MyCanvas extends JComponent
{
public void paint(Graphics g)
{
g.drawRect (10, 10, 200, 200);
}
}
public class DrawRectangle
{
public static void main(String[] a)
{
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 300, 300);
window.getContentPane().add(new MyCanvas());
window.setVisible(true);
}
}
Output:-