Posts

ID and Password Verification (String)

package String; import java.util.Scanner; public class EmailPassVer { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter your mail"); String email=sc.next(); Boolean tf=isValid(email); if(tf.equals(false)) { System.out.println("not valid email"); }else { System.out.println("Enter your password"); String pass=sc.next(); String eemail="bikas.shah1921@gmail.com"; String ppass="bikas123"; if(email.equals(eemail) && pass.equals(ppass)) { System.out.println("Login Sucessfully"); }else if (email.equals(eemail)||pass.equals(ppass)) { System.out.println("Email password not match"); }else if(email.isBlank()) { System.out.println("email cannot be blank"); }else if(email.isEmpty()) { System.out.println("email cannot be empty"); }else if(pass.isBlank()) { System.out.printl

A simple method using string to check whether the input password is correct or not

package String; import java.util.Scanner; public class EquilityTest { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter the password"); String pass=sc.nextLine(); String password="bikas"; if(pass.equals(password)) { System.out.println("Right password"); }else if(pass.equalsIgnoreCase(password)) { System.out.println("right Password"); }else if(pass.isEmpty()) { System.out.println("Cannot be empty"); }else if(pass.isBlank()) { System.out.println("Dont leave it blank"); } sc.close(); } }

JAVA(String Buffer and String Builder

 package String; public class StringTest { public static void main(String[] args) { /* * Example of immutable string * Immutable means unchangeable7 * Example of string buffer   */ String s="I teach in "; s.concat("Arniko school"); System.out.println(s); //to solve this problem we have string builder StringBuilder sb= new StringBuilder("I teach in "); sb.append("Arniko school "); System.out.println(sb); } }

Java Program to find average of Three numbers

 import java.util.Scanner; class Average{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many numbers are you goind to add"); int num = sc.nextInt(); int[] numbers = new int[num]; System.out.println("Enter the numbers one by one by pressing enter"); for(int i=0; i<num; i++){ numbers[i] = sc.nextInt(); } double avg=0; int sum =0; for(int i=0; i<num; i++){ sum = sum+numbers[i]; } avg=sum/num ; System.out.println("the avg is"+avg); } }

Java Program any letter to upper case Letter(JavaSWING) ActionListener

Image
import java.awt.event.*; import java.awt.*; import javax.swing.*; class MyFrame extends JFrame implements ActionListener{ Container c; JTextField t1; JButton b1; MyFrame(){ c=this.getContentPane(); c.setLayout(null); t1 = new JTextField(); t1.setBounds(100,50,210,50); c.add(t1); b1 = new JButton("CLick"); b1.setBounds(100,100,150,40); c.add(b1); b1.addActionListener(this); } public void actionPerformed(ActionEvent e){ String str =t1.getText(); t1.setText(str.toUpperCase()); } } class Uper{ public static void main(String[] args) { MyFrame f = new MyFrame(); f.setBounds(100,100,800,400); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle("to upper case"); f.setVisible(true); } } 

Java Swing Complete examples step by step(make a project with swing)

Image
 FIRST PROGRAM(JFRAME): import java.awt.*; import javax.swing.*; class MyFirstFrame{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("My First frame"); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(50,100,800,500); //for changing the icon we need create object of ImageIcon ImageIcon img = new ImageIcon("bikas.jpg"); frame.setIconImage(img.getImage()); Container c = frame.getContentPane(); //c.setBackground(Color.RED); c.setBackground(new Color(80, 149, 80)); } } OUTPUT:  Second  PROGRAM(JLABEL): import java.awt.*; import javax.swing.*; class MyLabel{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("JAVA"); frame.setBounds(50,250,1000,800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Container c=frame.getContentPane(); c.setLayout(null); /