Home
Classrooms
Courses
About Us
Resources
Members
More
E4.14
import java.util.*; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("input a number between 1000 and 999,999"); int x = in.nextInt(); String input = "" + x; String output = ""; int length = input.length(); int i = 0; int y = x; while(y > 0){ output = y%10 + output; i += 1; if(i%3 == 0){ output = "," + output; } y/=10; } System.out.println(output); } }
E4.13
import java.util.*; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("input any number with comma(s)"); String input = in.nextLine(); int length = input.length(); String output = ""; int comma_count = length / 4; for(int i = 0; i < comma_count; i++){ output = input.substring(length-3-(4*i),length-(4*i)) + output; } output = input.substring(0, length%4) + output; System.out.println(output); } }
E4.14
import java.util.*; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("input a number between 1000 and 999,999"); int x = in.nextInt(); String input = "" + x; String output = ""; int length = input.length(); int i = 0; int y = x; while(y > 0){ output = y%10 + output; i += 1; if(i%3 == 0){ output = "," + output; } y/=10; } System.out.println(output); } }
E4.13
import java.util.*; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("input any number with comma(s)"); String input = in.nextLine(); int length = input.length(); String output = ""; int comma_count = length / 4; for(int i = 0; i < comma_count; i++){ output = input.substring(length-3-(4*i),length-(4*i)) + output; } output = input.substring(0, length%4) + output; System.out.println(output); } }