Implement Java code to compare two characters for a competition.
Attribute 1 of character 1 will be numeric, and attribute 2 will be textual
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter details for character 1");
System.out.print("Enter attr11: ");
int attr11=sc.nextInt();
System.out.print("Enter attr21: ");
String attr21=sc.next();
System.out.println("Enter details for character 2");
System.out.print("Enter attr12: ");
int attr12=sc.nextInt();
System.out.print("Enter attr22: ");
String attr22=sc.next();
int compare = attr21.compareToIgnoreCase(attr22);
if (attr11>attr12 && compare>0){
System.out.println("Character 1 has won");
}
else{
System.out.println("Character 2 has won");
}
}
}
Comments
Leave a comment