02.11.2014, 08:17
Quote:
I program in java so here is solution -
Код:
package question2; import java.util.Scanner; public class Question2 { void main() { Scanner input = new Scanner(System.in); System.out.println("Enter an integer between 1000 and 9999: "); int num = input.nextInt(); System.out.println("Enter a digit (between 0 and 9): "); int d = input.nextInt(); System.out.println("Enter a character: "); char ch = input.nextLine.charAt(0);//thats how u enter a char String result = (ch-1);//it stores the final result int r,c = 1,f=num; while(num != 0) { r = num % 10; num = num/10; if(c==2 || c==4)result+=d; else result+=r; c++; } result+= (ch+1); System.out.println("Number was "+f+". Result : "+result); } } But should work... |
Furthermore, it doesn't work...
@OP:
In Java, a String cannot be modified. However, you can convert the string to a array of characters (******, in which you can modify each individual character.