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

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.
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
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 Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT