Become More Then A coder | Learn & Start Coding Now.
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
int[][] twodm = {
{10, 20, 30},
{40, 50, 60}
};
System.out.print("Original Array:\n");
print_array(twodm);
System.out.print("After changing the rows and columns of the said array:");
transpose(twodm);
}
private static void transpose(int[][] twodm) {
int[][] newtwodm = new int[twodm[0].length][twodm.length];
for (int i = 0; i < twodm.length; i++) {
for (int j = 0; j < twodm[0].length; j++) {
newtwodm[j][i] = twodm[i][j];
}
}
print_array(newtwodm);
}
private static void print_array(int[][] twodm) {
for (int i = 0; i < twodm.length; i++) {
for (int j = 0; j < twodm[0].length; j++) {
System.out.print(twodm[i][j] + " ");
}
System.out.println();
}
}
}
Q2) Write a program to design a screen using Awt that will take a user name and password. If
the user name and password are not same, raise an Exception with appropriate message.
User can have 3 login chances only. Use clear button to clear the TextFields.
------
setTitle(“Login “);
setSize(290,200);
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
Button btn=(Button)(ae.getSource());
if(attempt<3)
{
if((btn.getLabel())==”Clear”)
{
nametext.setText(“”);
passtext.setText(“”);
}
if((btn.getLabel()).equals(“Login”))
{
try
{
String user=nametext.getText();
String upass=passtext.getText();
if(user.compareTo(upass)==0)
{
msg.setText(“Valid”);
System.out.println(“Username is valid”);
}
else
{
throw new InvalidPasswordException();
}
}
catch(Exception e)
{
msg.setText(“Error”);
}
attempt++;
}
}
else
{
System.out.println(“you are using 3 attempt”);
System.exit(0);
}
}
public static void main(String args[])
{
PasswordDemo pd=new PasswordDemo();
pd.login();
}
}
0 Comments