Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static String k[] = new String[]{"x^2", "x", ""};
- public static void main(String[] args) {
- int a=1; // *********
- int b=0; // user data
- int c=0; // *********
- System.out.println(show(a, 0)+show(b, 1)+show(c,2)+"=0");
- }
- public static String show(int i, int pos) {
- if(i==0){
- return "";
- }
- if(pos==k.length){
- return ""+i;
- }
- String result = "";
- if(i<-1 || i>1) {
- result = (i > 0) ? "+"+i+k[pos] : ""+i+k[pos];
- }
- if(Math.abs(i)==1){
- result = (i>0) ? "+"+k[pos] : "-"+k[pos];
- }
- if(pos==0 && result.charAt(0)=='+') {
- return result.substring(1);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement