Answer to Question #204813 in Java | JSP | JSF for Karon Aldrich

Question #204813

Implement Java code to compare two characters for a competition.

Attribute 1 of character 1 will be numeric, and attribute 2 will be textual 


1
Expert's answer
2021-06-08T23:49:50-0400
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");
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS