标签:
判断:两个数x、y的正负性。
要求:不可以使用比较运算符,即"<",">","<=",">=","==","!="。
1 1 -1 1
Signs are not opposot Signs are opposite
import java.util.Scanner; public class Main16 { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { int a = input.nextInt(); int b = input.nextInt(); if(a*b>0) System.out.printf("Signs are not opposot \n"); else if(a*b<0) System.out.printf("Signs are opposite\n"); else System.out.printf("Signs can‘t be sure\n"); // String str1 = input.next(); // String str2 = input.next(); // // if ((str1.contains("-") && str2.contains("-")) || (!str1.contains("-") && !str2.contains("-"))) { // System.out.println("Signs are not opposot"); // } else if ((str1.contains("-") && !str2.contains("-")) || (!str1.contains("-") && str2.contains("-"))) { // System.out.println("Signs are opposite"); // } else{ // System.out.println("Signs can‘t be sure"); // } // } input.close(); } }
标签:
原文地址:http://www.cnblogs.com/airycode/p/5485564.html