Design an AWT application to check whether the number entered in textbox is prime or not. Get link Facebook X Pinterest Email Other Apps - April 04, 2019 Source Code:- import java.awt.*; import java.awt.event.*; class Prime extends Frame implements ActionListener { TextField tf1,tf2; public Prime() { setLayout(new FlowLayout()); Label lb1=new Label("Enter Number:"); Label lb2=new Label("The Number is:"); tf1=new TextField(15); tf2=new TextField(15); Button btn1=new Button("Calculate"); add(lb1); add(tf1); add(lb2); add(tf2); add(btn1); btn1.addActionListener(this); } public static void main(String ar[]) { Prime fr=new Prime(); fr.setSize(300,300); fr.setTitle("Calculate Prime"); fr.setVisible(true); } public void actionPerformed(ActionEvent ae) { int flag = 0,num; num=Integer.parseInt(tf1.getText()); for(int i = 2; i <= num/2; i++) { if(num % i == 0) { flag = 1; break; } } if (flag==0) tf2.setText("prime number."); else tf2.setText("not prime number."); } } Output :- Get link Facebook X Pinterest Email Other Apps Comments
Write a Java code to input height (in inches) and convert it into feet and inches. - April 04, 2019 Source Code:- import java.io.*; import java.util.*; class height { height() { int a,b,inch; Scanner s=new Scanner(System.in); System.out.println("Enter the Height in inches"); inch=s.nextInt(); a=inch/12; b=... Read more
Design an AWT application to calculate the factorial of a number. - April 04, 2019 Source Code:- import java.awt.*; import java.awt.event.*; class Factorial extends Frame implements ActionListener { TextField tf1,tf2; public Factorial() { setLayout(new FlowLayout()); Label lb1=new Label("Enter Number:"); Label lb2=new Label("Factorial is:"); tf1=new TextField(15); ... Read more
Comments
Post a Comment