Rgazzi ho un problema devo fare un ciclo che mi deve richimare un metodo e stampare il contenuto fino ad un certo valore, mi spiego meglio...
Praticamente devo richiamare tante volte la funzione di stampa con un nuovo valore di next(n) fino a che n==next(n)...come si fà????codice:public static int next(int n){ String s = Integer.toString(n); char[] array = s.toCharArray(); String s1 = "", s2 = ""; Arrays.sort(array); for(int i=0;i<array.length;i++){ s1 = s1.concat(Character.toString(array[i])); } for(int i=array.length-1;i>=0;i--){ s2 = s2.concat(Character.toString(array[i])); } int a = Integer.parseInt(s1); int b = Integer.parseInt(s2); int ris = b-a; return ris; } public static void stampaSequenza(int n){ System.out.println(next(n)); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); //while(n!=next(n)){ stampaSequenza(n); stampaSequenza(next(n)); stampaSequenza(next(next(n))); }
grazie mille

Rispondi quotando