HNDC 12/02 GROUP 2 |
Question 1 import javax.swing.JOptionPane; public class Question1 { final static double PI = 3.14159; public static void main(String[] args) { double radius, area, diameter, circumference; String str = ""; radius = Double.parseDouble(JOptionPane.showInputDialog("Enter the number of radius: ")); area = radius * radius * PI; diameter = 2 * radius; circumference = 2 * PI * radius; JOptionPane.showMessageDialog(null, str + String.format("The area for the circle of radius " + radius + " is " +area)); JOptionPane.showMessageDialog(null, str + String.format("The diameter for the circle of radius " + radius + " is " +diameter)); JOptionPane.showMessageDialog(null, str + String.format("The circumference for the circle of radius " + radius + " is " + circumference)); } }
The Output
Question 2 import javax.swing.JOptionPane; public class Question2
{
public static void main( String args[] ) { int number; int digit1; int digit2; int digit3; int digit4; int digit5;
String str = ""; number = Integer.parseInt(JOptionPane.showInputDialog( "Enter five digit integer: " ));
digit1 = number / 10000; digit2 = number % 10000 / 1000; digit3 = number % 10000 % 1000 / 100; digit4 = number % 10000 % 1000 % 100 / 10; digit5 = number % 10000 % 1000 % 100 % 10;
JOptionPane.showMessageDialog(null, String.format("%d %d %d %d %d\n", digit1, digit2, digit3, digit4, digit5 )); }
}
The Output
Question 3 import javax.swing.JOptionPane; public class Question3
{
public static void main(String[] args)
{
int x; x = Integer.parseInt(JOptionPane.showInputDialog("Enter the number whether the number is even or odd: ")); numberinteger(x); } public static void numberinteger(int x){ if(x % 2 == 0)
{
JOptionPane.showMessageDialog(null, "The number is even");
}
else
{