Question

In: Computer Science

Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending...

Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending in 3. • Write a for loop to display a string entered by the user backwards.

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 1 :

Here a new java with name "main.java" is created, which contains following code.

main.java :

/*Java program to find numbers between 13-93 that ends with 3*/
//Class Main
public class Main
{
//main method
   public static void main(String[] args) {
   //declaring variable
   int i;
   for (i=13;i<=93;i++)
   {
   //checking if number is end with 3
   if(Integer.toString(i).endsWith("3")){
   //display number
       System.out.print(i+" ");
   }
   }
   }
}

======================================================

Output : Compile and Run main.java to get the screen as shown below

Screen 1 :main.java

*********************************

Question 2 :

main.c :

/*Write a for loop to display a string entered by the user backwards.*/
import java.util.*;
//Class Main
public class Main
{
//main method
   public static void main(String[] args) {
   //creating object of scanner class
   Scanner scanner=new Scanner(System.in);
   //asking user to enter string
   System.out.println("Enter a string : ");
   //reading string
   String inputString=scanner.nextLine();
   //converting string to character array
   char[] strChar = inputString.toCharArray();
   //finding length of string
   int strLength=strChar.length;
   //using for loop to print string backwords
   for(int i=strLength-1;i>=0;i--)
   {
   //display string in backwords
   System.out.print(strChar[i]);
   }
   }
}
================================

Output :Compile and run above program to get the screen as shown below

Screen 1:Screen asking to enter string

Screen 2 :Screen showing string backwords

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199   Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
JAVA Write a for loop which will display this set of values 1,3,5,7,9.
JAVA Write a for loop which will display this set of values 1,3,5,7,9.
JAVA: Display all even numbers between 1 and 20 --Optional write a program that reads in...
JAVA: Display all even numbers between 1 and 20 --Optional write a program that reads in 20 numbers. A method with an int parameter should display whether the number is odd or even for the number passed
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.(java language)
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax. in java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT