import java.util.Scanner; public class ex4 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int input = -1; do{ try{ input = Integer.parseInt(in.nextLine()); if(input == 0 || input % 2 == 0) throw new Exception("Put an even and positive number"); for (int y = 0; y < input; y++){ for (int x = 0; x < input; x++){ if(((x <= y) && (x <= (input-y-1)))||(x >= y) && (x >= (input-y-1))) System.out.print("*"); else System.out.print(" "); } System.out.println(); } System.out.println(); } catch (Exception e){ System.out.println("Input INTEGER"); } }while(input == 0); for(int i = 0; i < input; i++){ for(int j = 0; j < input; j++){ // if(j == 0 || j == input - 1) System.out.print("*"); if(j < i && i <= input / 2) System.out.print("*"); continue; if(i == j || i == input / 2) System.out.print("*"); else System.out.print(" "); } System.out.print("\n"); } } }
<HTML> <body> </body> <script> function Calculator() { let methods = { "-" : (a, b) => a - b, "+" : (a, b) => a + b }; //methods is an object which keeps key for operators //and value to return the actual operation values //each returns the result of operation that key(operator) does this.calculate = function (str){ //calculate is one element in the function Calculator //it takes the string and returns the value //in the function element list is delimeted by , not ; let split = str.split(" "), a = +split[0], op = split[1], b = split [2] if(!methods[op] || isNaN(a) || isNaN(b)) { return NaN; // error handling } return methods[op](a,b); } this.addMethod = function(name, func){ methods[name] = func; //this is how to add new key and ele to object } } let powerCalc = new Calculator; powerCalc.addMethod("*&
댓글
댓글 쓰기