SDUT- 3339 計算長方形的周長和麵積(類和物件)
阿新 • • 發佈:2018-12-15
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); String s; int i, l, r; while(cin.hasNext()) { s = cin.nextLine(); l = r = 0; char a[] = s.toCharArray(); for(i = 0; i < a.length; i++) { if(a[i] == '-')break; } if(i < a.length) { System.out.println("0 0 0 0"); continue; } for(i = 0; i < a.length; i++) { if(a[i] == ' '){break;} l *= 10; l += a[i] - '0'; } if(i == a.length)r = l; else { for(i++; i < a.length; i++) { r *= 10; r += a[i] - '0'; } } System.out.println(l + " " + r + " " + (l + r) * 2 + " " + l * r); } cin.close(); } }