Write a while (or for) statement to print all the digits of an int type variable x, one digit per line. For example, if int x

Answers

Answer 1

Complete Question:

Write a while (or for) statement to print all the digits of an int type variable x, one digit per line For example, if int x 38625, then the output should be in 5 lines as 60 (Hint: You may use built-in method to get a String representation of x then print out each character in String)

***** Java *****

Answer:

import java.util.*;

public class Main{  

public static void main(String args[])  {  

Scanner input = new Scanner(System.in);

System.out.print("Enter an integer: ");

int x = input.nextInt();

String str = Integer.toString(x);  

for(int i =0;i<str.length();i++)  {

    System.out.println(str.charAt(i));

}

}  

}  

Explanation:

This line prompts user for input

System.out.print("Enter an integer: ");

This line gets user input

int x = input.nextInt();

This line converts user input to string

String str = Integer.toString(x);  

The following loop iterates through the converted string

for(int i =0;i<str.length();i++)  {

This prints each character on the string

    System.out.println(str.charAt(i));

}


Related Questions

which of these are correctly formatted python lists? check all that apply
Options
-list1=(race, cars, trucks, bikes)
-list2=["computer science', 'math', 'psychology']
-list3=('summer', 'winter', 'spring')
-list5[52, 24, 71, 56]​

Answers

The first and third option are actually tuples, not lists. Tuples and lists are identical except for the fact that you cannot change the elements in a tuple but you can in a list. The last option is incorrect because there is no equal sign that assigns those numbers to the variable name list5.

The only option that makes sense is option 2, list2

Answer:

B, C, and E :)

Explanation:

are you absent minded because you are thinking of an online activity?​

Answers

Answer:

No . It doesn't mean that person thinking an online activity is absent minded bcoz while we are thinking any activities our mind is working and while doing anything there is presence of our mind so i don't think thinking an online activity is absentminded .

In my idea.

Font size means the height of characters.
True
False​

Answers

True..................

Answer:

Hey dude....

Explanation:

This is ur answer....

True

Hope it helps!

Brainliest pls!

Follow me! :)

Other Questions
WILL MARK BRIANLIEST IF QUESTION ANSWERED HONESTLY!!1-If your not from the US what do you think about the U.S.?2-If you do live in the U.S. what did you think of the state of Wisconsin. *what is the first thing that comes to mind* How do misconceptions originate? ____ viven en La Pampa, Argentina.A. Los deportistasB. Los maestrosC. Los gauchosD. Los estudiantes 6. Boys reach the age of puberty earlier than girlsGirls and boys experience rapid mental growthBoys and girls like to be alone more than to be with friendsChanges that happen to boys and girls occur in all dimensiBoys grow beard or mustache Can someone plz help sanhi ng paglaganp ng crab mentality sa bansa Please help :) i need help which source has the widest range of residence time 2x+y=8 and 6x-y=5...which variable should be eliminated and why what is the quotient when x^3-5x^2+2x+5 is divided by x-2 Which answer is the best revision of the inappropriate shift in verb tense?Question 6 options:Dorothy wanders along the yellow brick road with Toto sitting in her basket, searched for clues about how to find the Emerald City.Dorothy wandered along the yellow brick road with Toto sitting in her basket, searches for clues about how to find the Emerald City.Dorothy wanders along the yellow brick road with Toto sitting in her basket, searching for clues about how to find the Emerald City.Dorothy wanders along the yellow brick road with Toto sitting in her basket, searches for clues about how to find the Emerald City. The legal theory under which states were able to reject federal laws deemed unconstitutional was known asnaturalization.nullification.resolution.sedition. NEED HELP ASAP THIS DUE IN LIKE 5 MINUTES!!!! Whats 8/3 - 2/8 ? Need help Which word goes best with understanding? Word Bank:composed abandonment illumination 1.) True or False. Scientists have drilled through the crust to reach the mantle. During the Progressive Era, one goal of state-level political reformers was to -A prevent party leaders from amending campaign platformsB increase the influence of business owners on regulatory legislationC promote the principle of direct democracyD limit the use of judicial review by circuit courts Please help! Thanks guys :) Which of the following represents a function?a.(5, 1), (5, 2), (5, 3), (5, 4)b.(2, 3), (4, 3), (-2, -3), (-4, -3)c.(3, 4), (-3, 2), (3, 8), (5, 5)d.(-1, 2), (-2, 1), (-1, -2), (-2, -1) check the correctness of P=2mE/t where the symbols have usual meaning.